<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222"><meta name="generator" content="Hexo 7.1.1">

  <link rel="apple-touch-icon" sizes="180x180" href="/images/avatar.jpg">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/avatar.jpg">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/avatar.jpg">
  <link rel="mask-icon" href="/images/avatar.jpg" color="#222">
  <meta name="msvalidate.01" content="4AF2328B2035748153A041B7EEF3D15C">

<link rel="stylesheet" href="/css/main.css">

<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Noto+Serif+SC:300,300italic,400,400italic,700,700italic%7CLobster:300,300italic,400,400italic,700,700italic%7CPingFang+SC:300,300italic,400,400italic,700,700italic%7CRoboto+Mono:300,300italic,400,400italic,700,700italic&display=swap&subset=latin,latin-ext">

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" integrity="sha256-wiz7ZSCn/btzhjKDQBms9Hx4sSeUYsDrTLg7roPstac=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.33/fancybox/fancybox.css" integrity="sha256-gkQVf8UKZgQ0HyuxL/VnacadJ+D2Kox2TCEBuNQg5+w=" crossorigin="anonymous">

<script class="next-config" data-name="main" type="application/json">{"hostname":"ethanliu6.github.io","root":"/","images":"/images","scheme":"Gemini","darkmode":false,"version":"8.19.2","exturl":true,"sidebar":{"position":"left","display":"always","padding":12,"offset":18},"copycode":{"enable":true,"style":"mac"},"fold":{"enable":true,"height":300},"bookmark":{"enable":true,"color":"#222","save":"manual"},"mediumzoom":true,"lazyload":true,"pangu":false,"comments":{"style":"buttons","active":"changyan","storage":true,"lazyload":false,"nav":null,"activeClass":"changyan"},"stickytabs":false,"motion":{"enable":true,"async":false,"transition":{"menu_item":"fadeInDown","post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":6,"unescape":false,"preload":false}}</script><script src="/js/config.js"></script>

    <meta name="description" content="这是一篇关于MYSQL基础语法（上）">
<meta property="og:type" content="article">
<meta property="og:title" content="MYSQL基础语法（上）">
<meta property="og:url" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/index.html">
<meta property="og:site_name" content="&lt;font color&#x3D;&#39;white&#39; &gt;Ethan の Blog&lt;&#x2F;font&gt;">
<meta property="og:description" content="这是一篇关于MYSQL基础语法（上）">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E5%85%B3%E7%B3%BB%E5%9E%8B%E6%95%B0%E6%8D%AE%E5%BA%93%E5%9B%BE%E8%A7%A3.bmp">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/mysql%E5%AE%89%E8%A3%85%E5%9B%BE%E8%A7%A31.bmp">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/mysql%E5%AE%89%E8%A3%85%E5%9B%BE%E8%A7%A32.bmp">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/mysql%E5%AE%89%E8%A3%85%E5%9B%BE%E8%A7%A33.bmp">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/mysql%E5%AE%89%E8%A3%85%E5%9B%BE%E8%A7%A34.bmp">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/mysql%E5%AE%89%E8%A3%85%E5%9B%BE%E8%A7%A35.bmp">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/mysql%E5%AE%89%E8%A3%85%E5%9B%BE%E8%A7%A36.bmp">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/mysql%E5%AE%89%E8%A3%85%E5%9B%BE%E8%A7%A37.bmp">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/mysql%E5%AE%89%E8%A3%85%E5%9B%BE%E8%A7%A38.bmp">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/mysql%E5%AE%89%E8%A3%85%E5%9B%BE%E8%A7%A39.bmp">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/mysql%E5%AE%89%E8%A3%85%E5%9B%BE%E8%A7%A310.bmp">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/mysql%E5%AE%89%E8%A3%85%E5%9B%BE%E8%A7%A311.bmp">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/mysql%E5%AE%89%E8%A3%85%E5%9B%BE%E8%A7%A312.bmp">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/mysql%E5%AE%89%E8%A3%85%E5%9B%BE%E8%A7%A313.bmp">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/mysql%E5%AE%89%E8%A3%85%E5%9B%BE%E8%A7%A314.bmp">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/mysql%E5%AE%89%E8%A3%85%E5%9B%BE%E8%A7%A315.bmp">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/mysql%E5%AE%89%E8%A3%85%E5%9B%BE%E8%A7%A316.bmp">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/mysql%E5%AE%89%E8%A3%85%E5%9B%BE%E8%A7%A317.bmp">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/mysql%E5%AE%89%E8%A3%85%E5%9B%BE%E8%A7%A318.bmp">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/mysql%E5%AE%89%E8%A3%85%E5%9B%BE%E8%A7%A319.bmp">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/mysql%E5%AE%89%E8%A3%85%E5%9B%BE%E8%A7%A320.bmp">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/1550408825267.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/mysql%E5%90%AF%E5%8A%A802.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/1550409365086.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E6%B5%8B%E8%AF%95mysql%E6%98%AF%E5%90%A6%E8%BF%9E%E6%8E%A5%E6%88%90%E5%8A%9F2.PNG">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/dos%E7%AA%97%E5%8F%A3%E6%B5%8B%E8%AF%95%E6%98%AF%E5%90%A6%E8%BF%9E%E6%8E%A5%E6%88%90%E5%8A%9F.PNG">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E6%B5%8B%E8%AF%95mysql%E6%98%AF%E5%90%A6%E8%BF%9E%E6%8E%A5%E6%88%90%E5%8A%9F2.PNG">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/1550409365086.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/image-20200609100334374.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/1550409365086.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E5%AE%9E%E4%BD%93%E7%B1%BB%E4%B8%8E%E8%A1%A8%E7%9A%84%E5%AF%B9%E5%BA%94%E5%85%B3%E7%B3%BB.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E6%95%B0%E6%8D%AE%E5%BA%93%E5%86%85%E9%83%A8%E5%AD%98%E5%82%A8%E7%BB%93%E6%9E%84.PNG">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E7%9B%B4%E6%8E%A5%E5%88%9B%E5%BB%BA%E6%95%B0%E6%8D%AE%E5%BA%93.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E5%88%A4%E6%96%AD%E6%98%AF%E5%90%A6%E5%AD%98%E5%9C%A8%E5%B9%B6%E5%88%9B%E5%BB%BA%E6%95%B0%E6%8D%AE%E5%BA%93.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E5%88%9B%E5%BB%BA%E6%95%B0%E6%8D%AE%E5%BA%93%E5%B9%B6%E6%8C%87%E5%AE%9A%E5%AD%97%E7%AC%A6%E9%9B%86.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E6%9F%A5%E7%9C%8B%E6%89%80%E6%9C%89%E6%95%B0%E6%8D%AE%E5%BA%93.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E6%9F%A5%E7%9C%8B%E6%9F%90%E4%B8%AA%E6%95%B0%E6%8D%AE%E5%BA%93%E7%9A%84%E5%AE%9A%E4%B9%89%E4%BF%A1%E6%81%AF.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E4%BF%AE%E6%94%B9%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AD%97%E7%AC%A6%E9%9B%86.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E5%88%A0%E9%99%A4%E6%95%B0%E6%8D%AE%E5%BA%93.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E6%9F%A5%E7%9C%8B%E6%AD%A3%E5%9C%A8%E4%BD%BF%E7%94%A8%E7%9A%84%E6%95%B0%E6%8D%AE%E5%BA%93.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E4%BD%BF%E7%94%A8db1%E6%95%B0%E6%8D%AE%E5%BA%93.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/MYSQL%E5%B8%B8%E7%94%A8%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/1550410505421.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E6%9F%A5%E7%9C%8B%E6%9F%90%E4%B8%AA%E6%95%B0%E6%8D%AE%E5%BA%93%E4%B8%AD%E7%9A%84%E6%89%80%E6%9C%89%E8%A1%A8.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E6%9F%A5%E7%9C%8Bstudent%E8%A1%A8%E7%9A%84%E7%BB%93%E6%9E%84.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E6%9F%A5%E7%9C%8Bstudent%E7%9A%84%E5%88%9B%E5%BB%BA%E8%A1%A8SQL%E8%AF%AD%E5%8F%A5.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E7%9B%B4%E6%8E%A5%E5%88%A0%E9%99%A4%E8%A1%A8.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E5%88%A4%E6%96%AD%E8%A1%A8%E5%AD%98%E5%9C%A8%E5%B9%B6%E5%88%A0%E9%99%A4.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E6%B7%BB%E5%8A%A0%E5%AD%97%E6%AE%B5.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E4%BF%AE%E6%94%B9%E5%AD%97%E6%AE%B5%E7%B1%BB%E5%9E%8B.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E4%BF%AE%E6%94%B9%E8%A1%A8%E5%AD%97%E6%AE%B5%E5%90%8D%E7%A7%B0.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E5%88%A0%E9%99%A4%E5%AD%97%E6%AE%B5.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E4%BF%AE%E6%94%B9%E8%A1%A8%E5%90%8D.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E4%BF%AE%E6%94%B9%E5%AD%97%E7%AC%A6%E9%9B%86.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E6%B7%BB%E5%8A%A0%E9%83%A8%E5%88%86%E6%95%B0%E6%8D%AE.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E6%89%80%E6%9C%89%E5%AD%97%E6%AE%B5%E9%83%BD%E6%B7%BB%E5%8A%A0%E6%95%B0%E6%8D%AE.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E6%B7%BB%E5%8A%A0%E6%89%80%E6%9C%89%E5%AD%97%E6%AE%B5%E6%95%B0%E6%8D%AE.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E4%BF%AE%E6%94%B9%E6%89%80%E6%9C%89%E6%95%B0%E6%8D%AE.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E5%B8%A6%E6%9D%A1%E4%BB%B6%E4%BF%AE%E6%94%B9.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E4%B8%80%E6%AC%A1%E6%80%A7%E4%BF%AE%E6%94%B92%E4%B8%AA%E5%AD%97%E6%AE%B5.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/truncate.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E5%88%A0%E9%99%A4%E6%BB%A1%E8%B6%B3%E6%9D%A1%E4%BB%B6%E7%9A%84%E8%AE%B0%E5%BD%95.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E5%88%A0%E9%99%A4%E6%89%80%E6%9C%89%E8%AE%B0%E5%BD%95.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E6%9F%A5%E8%AF%A2%E6%89%80%E6%9C%89%E5%88%97.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E6%9F%A5%E8%AF%A2%E6%89%80%E6%9C%89%E5%88%97.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E6%9F%A5%E8%AF%A2%E6%8C%87%E5%AE%9A%E5%AD%97%E6%AE%B5.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E6%9F%A5%E8%AF%A2%E5%AD%97%E6%AE%B5%E5%88%AB%E5%90%8D.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/1550289641391.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E6%B7%BB%E5%8A%A0%E6%95%B0%E5%AD%A6%E5%92%8C%E8%8B%B1%E8%AF%AD%E6%88%90%E7%BB%A9.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E6%9F%A5%E8%AF%A2math%E5%92%8Cenglish%E7%9A%84%E5%92%8C.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E7%BB%84%E5%90%88%E6%9F%A5%E8%AF%A2%E7%BB%93%E6%9E%9C%E5%8F%96%E5%88%AB%E5%90%8D.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E6%9F%A5%E8%AF%A2%E6%89%80%E6%9C%89%E5%88%97%E6%95%B0%E6%8D%AE%E5%92%8C%E5%8F%82%E4%B8%8E%E8%BF%90%E7%AE%97.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E8%A0%95%E8%99%AB%E5%A4%8D%E5%88%B6-1597202630793.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/where%E6%9F%A5%E8%AF%A201.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/where%E6%9F%A5%E8%AF%A202.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/where%E6%9F%A5%E8%AF%A203.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/where%E6%9F%A5%E8%AF%A204.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/where%E6%9F%A5%E8%AF%A205.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/where%E6%9F%A5%E8%AF%A206.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/where%E6%9F%A5%E8%AF%A208.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/where%E6%9F%A5%E8%AF%A208.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/where%E6%9F%A5%E8%AF%A207.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/where%E6%9F%A5%E8%AF%A209.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/where%E6%9F%A5%E8%AF%A211.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/where%E6%9F%A5%E8%AF%A210.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/where%E6%9F%A5%E8%AF%A211.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/where%E6%9F%A5%E8%AF%A212.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/orderby01.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/orderby01.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/orderby02.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E8%81%9A%E5%90%88%E5%87%BD%E6%95%B001.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E8%81%9A%E5%90%88%E5%87%BD%E6%95%B002.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E8%81%9A%E5%90%88%E5%87%BD%E6%95%B003.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E8%81%9A%E5%90%88%E5%87%BD%E6%95%B004.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E6%80%BB%E5%92%8C%E5%80%BC.bmp">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E6%80%BB%E5%92%8C%E5%80%BC2.bmp">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E6%80%BB%E5%92%8C%E5%80%BC3.bmp">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E8%81%9A%E5%90%88%E5%87%BD%E6%95%B006.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E8%81%9A%E5%90%88%E5%87%BD%E6%95%B007.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E8%81%9A%E5%90%88%E5%87%BD%E6%95%B005.png">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E5%88%86%E7%BB%84%E5%9B%BE%E8%A7%A31.bmp">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E5%88%86%E7%BB%84%E5%9B%BE%E8%A7%A32.bmp">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E5%88%86%E7%BB%84%E5%9B%BE%E8%A7%A33.bmp">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E5%88%86%E7%BB%84%E5%9B%BE%E8%A7%A34.bmp">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E5%88%86%E7%BB%84%E5%9B%BE%E8%A7%A35.bmp">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E5%88%86%E7%BB%84%E5%9B%BE%E8%A7%A36.bmp">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E5%88%86%E7%BB%84%E5%9B%BE%E8%A7%A37.bmp">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E5%88%86%E7%BB%84%E5%9B%BE%E8%A7%A38.bmp">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E5%88%86%E7%BB%84%E5%9B%BE%E8%A7%A39.bmp">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E5%88%86%E7%BB%84%E5%9B%BE%E8%A7%A310.bmp">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E5%88%86%E7%BB%84%E5%9B%BE%E8%A7%A311.bmp">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E5%88%86%E7%BB%84%E5%9B%BE%E8%A7%A312.bmp">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E5%88%86%E7%BB%84%E5%9B%BE%E8%A7%A313.bmp">
<meta property="og:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E5%88%86%E7%BB%84%E5%9B%BE%E8%A7%A314.bmp">
<meta property="article:published_time" content="2024-04-29T16:00:00.000Z">
<meta property="article:modified_time" content="2024-05-05T17:48:46.382Z">
<meta property="article:author" content="Ethan Liu">
<meta property="article:tag" content="Java">
<meta property="article:tag" content="MySQL">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/img/%E5%85%B3%E7%B3%BB%E5%9E%8B%E6%95%B0%E6%8D%AE%E5%BA%93%E5%9B%BE%E8%A7%A3.bmp">


<link rel="canonical" href="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":true,"permalink":"http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/","path":"2024/04/30/JavaNotes/MySQL/day01/day01-MySQL基础笔记/","title":"MYSQL基础语法（上）"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>MYSQL基础语法（上） | <font color='white' >Ethan の Blog</font></title>
  








  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
<style>.darkmode--activated{--body-bg-color:#282828;--content-bg-color:#333;--card-bg-color:#555;--text-color:#ccc;--blockquote-color:#bbb;--link-color:#ccc;--link-hover-color:#eee;--brand-color:#ddd;--brand-hover-color:#ddd;--table-row-odd-bg-color:#282828;--table-row-hover-bg-color:#363636;--menu-item-bg-color:#555;--btn-default-bg:#222;--btn-default-color:#ccc;--btn-default-border-color:#555;--btn-default-hover-bg:#666;--btn-default-hover-color:#ccc;--btn-default-hover-border-color:#666;--highlight-background:#282b2e;--highlight-foreground:#a9b7c6;--highlight-gutter-background:#34393d;--highlight-gutter-foreground:#9ca9b6}.darkmode--activated img{opacity:.75}.darkmode--activated img:hover{opacity:.9}.darkmode--activated code{color:#69dbdc;background:0 0}button.darkmode-toggle{z-index:9999}.darkmode-ignore,img{display:flex!important}.beian img{display:inline-block!important}</style></head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <div class="column">
      <header class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <p class="site-title"><font color='white' >Ethan の Blog</font></p>
      <i class="logo-line"></i>
    </a>
      <p class="site-subtitle" itemprop="description"><font color='#FDABC1' size=3>清醒的停留，胜过——盲目的前行</font></p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger" aria-label="搜索" role="button">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a></li><li class="menu-item menu-item-关于我"><a href="/aboutme/" rel="section"><i class="fa fa-user fa-fw"></i>关于我</a></li><li class="menu-item menu-item-tags"><a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签<span class="badge">18</span></a></li><li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类<span class="badge">14</span></a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档<span class="badge">53</span></a></li><li class="menu-item menu-item-love"><a href="/categories/Love/" rel="section"><i class="fas fa-heart fa-fw"></i>Love</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup"><div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" maxlength="80"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close" role="button">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="search-result-container no-result">
  <div class="search-result-icon">
    <i class="fa fa-spinner fa-pulse fa-5x"></i>
  </div>
</div>

    </div>
  </div>

</header>
        
  
  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%AD%A6%E4%B9%A0%E7%9B%AE%E6%A0%87"><span class="nav-number">1.</span> <span class="nav-text">学习目标</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E4%BB%8A%E6%97%A5%E9%87%8D%E7%82%B9"><span class="nav-number">2.</span> <span class="nav-text">今日重点</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%95%B0%E6%8D%AE%E5%BA%93%E8%BF%9E%E6%8E%A5%E5%A4%B1%E8%B4%A5"><span class="nav-number">3.</span> <span class="nav-text">数据库连接失败</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E8%BF%9E%E6%8E%A5%E6%95%B0%E6%8D%AE%E5%BA%93%E5%91%BD%E4%BB%A4"><span class="nav-number">4.</span> <span class="nav-text">连接数据库命令</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%AD%A6%E4%B9%A0%E5%86%85%E5%AE%B9"><span class="nav-number"></span> <span class="nav-text">学习内容</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%95%B0%E6%8D%AE%E5%BA%93%E7%9A%84%E5%9F%BA%E6%9C%AC%E7%9F%A5%E8%AF%86"><span class="nav-number">1.</span> <span class="nav-text">1.数据库的基本知识</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%9B%AE%E6%A0%87"><span class="nav-number">1.1.</span> <span class="nav-text">目标</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%AE%B2%E8%A7%A3"><span class="nav-number">1.2.</span> <span class="nav-text">讲解</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#%E4%BB%80%E4%B9%88%E6%98%AF%E6%95%B0%E6%8D%AE%E5%BA%93"><span class="nav-number">1.2.1.</span> <span class="nav-text">什么是数据库</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%95%B0%E6%8D%AE%E7%9A%84%E5%AD%98%E5%82%A8%E6%96%B9%E5%BC%8F"><span class="nav-number">1.3.</span> <span class="nav-text">数据的存储方式</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#%E6%95%B0%E6%8D%AE%E5%BA%93%E7%9A%84%E4%BC%98%E7%82%B9"><span class="nav-number">1.3.1.</span> <span class="nav-text">数据库的优点</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%B8%B8%E8%A7%81%E6%95%B0%E6%8D%AE%E5%BA%93"><span class="nav-number">1.3.2.</span> <span class="nav-text">常见数据库</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%B0%8F%E7%BB%93"><span class="nav-number">1.4.</span> <span class="nav-text">小结</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%85%B3%E7%B3%BB%E5%9E%8B%E6%95%B0%E6%8D%AE%E5%BA%93"><span class="nav-number">2.</span> <span class="nav-text">2.关系型数据库</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%95%B0%E6%8D%AE%E5%BA%93%E7%9A%84%E5%AE%89%E8%A3%85"><span class="nav-number">3.</span> <span class="nav-text">3.数据库的安装</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%9B%AE%E6%A0%87-1"><span class="nav-number">3.1.</span> <span class="nav-text">目标</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%AE%B2%E8%A7%A3-1"><span class="nav-number">3.2.</span> <span class="nav-text">讲解</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%B0%8F%E7%BB%93-1"><span class="nav-number">3.3.</span> <span class="nav-text">小结</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%91%BD%E4%BB%A4%E8%A1%8C%E5%AE%A2%E6%88%B7%E7%AB%AF%E8%BF%9E%E6%8E%A5%E6%9C%8D%E5%8A%A1%E5%99%A8%E6%B5%8B%E8%AF%95%E6%98%AF%E5%90%A6%E5%AE%89%E8%A3%85%E6%88%90%E5%8A%9F"><span class="nav-number">4.</span> <span class="nav-text">4.命令行客户端连接服务器(测试是否安装成功)</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%9B%AE%E6%A0%87-2"><span class="nav-number">4.1.</span> <span class="nav-text">目标</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%AE%B2%E8%A7%A3-2"><span class="nav-number">4.2.</span> <span class="nav-text">讲解</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%B0%8F%E7%BB%93-2"><span class="nav-number">4.3.</span> <span class="nav-text">小结</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%9B%BE%E5%BD%A2%E7%95%8C%E9%9D%A2datagrip%E5%AE%A2%E6%88%B7%E7%AB%AF"><span class="nav-number">5.</span> <span class="nav-text">5、图形界面DataGrip客户端</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%9B%AE%E6%A0%87-3"><span class="nav-number">5.1.</span> <span class="nav-text">目标</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%AE%B2%E8%A7%A3-3"><span class="nav-number">5.2.</span> <span class="nav-text">讲解</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%B0%8F%E7%BB%93-3"><span class="nav-number">5.3.</span> <span class="nav-text">小结</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%8D%B8%E8%BD%BD"><span class="nav-number">6.</span> <span class="nav-text">6、卸载</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%B8%8E%E6%95%B0%E6%8D%AE%E5%BA%93%E8%A1%A8%E8%AE%B0%E5%BD%95%E7%9A%84%E5%85%B3%E7%B3%BB"><span class="nav-number">7.</span> <span class="nav-text">7、服务器与数据库、表、记录的关系</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%9B%AE%E6%A0%87-4"><span class="nav-number">7.1.</span> <span class="nav-text">目标</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%AE%B2%E8%A7%A3-4"><span class="nav-number">7.2.</span> <span class="nav-text">讲解</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%AE%9E%E4%BD%93%E7%B1%BB%E4%B8%8E%E8%A1%A8%E7%9A%84%E5%AF%B9%E5%BA%94%E5%85%B3%E7%B3%BB"><span class="nav-number">7.2.1.</span> <span class="nav-text">实体类与表的对应关系</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%B0%8F%E7%BB%93-4"><span class="nav-number">7.3.</span> <span class="nav-text">小结</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#sql%E8%AF%AD%E5%8F%A5%E7%9A%84%E5%88%86%E7%B1%BB%E5%92%8C%E8%AF%AD%E6%B3%95"><span class="nav-number">8.</span> <span class="nav-text">8、SQL语句的分类和语法</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%9B%AE%E6%A0%87-5"><span class="nav-number">8.1.</span> <span class="nav-text">目标</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%AE%B2%E8%A7%A3-5"><span class="nav-number">8.2.</span> <span class="nav-text">讲解</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#%E4%BB%80%E4%B9%88%E6%98%AFsql"><span class="nav-number">8.2.1.</span> <span class="nav-text">什么是SQL</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#sql%E7%89%B9%E7%82%B9"><span class="nav-number">8.2.2.</span> <span class="nav-text">SQL特点</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#sql%E4%BD%9C%E7%94%A8"><span class="nav-number">8.2.3.</span> <span class="nav-text">SQL作用</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#sql%E8%AF%AD%E5%8F%A5%E5%88%86%E7%B1%BB"><span class="nav-number">8.2.4.</span> <span class="nav-text">SQL语句分类</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#sql%E5%AD%A6%E4%B9%A0%E6%96%B9%E5%90%91"><span class="nav-number">8.2.5.</span> <span class="nav-text">SQL学习方向</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#sql%E9%80%9A%E7%94%A8%E8%AF%AD%E6%B3%95"><span class="nav-number">8.2.6.</span> <span class="nav-text">SQL通用语法</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#ddl%E5%88%9B%E5%BB%BA%E6%95%B0%E6%8D%AE%E5%BA%93"><span class="nav-number">9.</span> <span class="nav-text">9、DDL创建数据库</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%9B%AE%E6%A0%87-6"><span class="nav-number">9.1.</span> <span class="nav-text">目标</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%AE%B2%E8%A7%A3-6"><span class="nav-number">9.2.</span> <span class="nav-text">讲解</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%88%9B%E5%BB%BA%E6%95%B0%E6%8D%AE%E5%BA%93"><span class="nav-number">9.2.1.</span> <span class="nav-text">创建数据库</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E6%9F%A5%E7%9C%8B%E6%95%B0%E6%8D%AE%E5%BA%93"><span class="nav-number">9.2.2.</span> <span class="nav-text">查看数据库</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%B0%8F%E7%BB%93-5"><span class="nav-number">9.3.</span> <span class="nav-text">小结</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#ddl%E4%BF%AE%E6%94%B9%E5%92%8C%E5%88%A0%E9%99%A4%E6%95%B0%E6%8D%AE%E5%BA%93"><span class="nav-number">10.</span> <span class="nav-text">10、DDL修改和删除数据库</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%9B%AE%E6%A0%87-7"><span class="nav-number">10.1.</span> <span class="nav-text">目标</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%AE%B2%E8%A7%A3-7"><span class="nav-number">10.2.</span> <span class="nav-text">讲解</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#%E4%BF%AE%E6%94%B9%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AD%97%E7%AC%A6%E9%9B%86"><span class="nav-number">10.2.1.</span> <span class="nav-text">修改数据库字符集</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%B0%8F%E7%BB%93-6"><span class="nav-number">10.3.</span> <span class="nav-text">小结</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#ddl%E4%BD%BF%E7%94%A8%E6%95%B0%E6%8D%AE%E5%BA%93"><span class="nav-number">11.</span> <span class="nav-text">11、DDL使用数据库</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%9B%AE%E6%A0%87-8"><span class="nav-number">11.1.</span> <span class="nav-text">目标</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%AE%B2%E8%A7%A3-8"><span class="nav-number">11.2.</span> <span class="nav-text">讲解</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%B0%8F%E7%BB%93-7"><span class="nav-number">11.3.</span> <span class="nav-text">小结</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#ddl%E5%88%9B%E5%BB%BA%E8%A1%A8"><span class="nav-number">12.</span> <span class="nav-text">12、DDL创建表</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%9B%AE%E6%A0%87-9"><span class="nav-number">12.1.</span> <span class="nav-text">目标</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%AE%B2%E8%A7%A3-9"><span class="nav-number">12.2.</span> <span class="nav-text">讲解</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%B0%8F%E7%BB%93-8"><span class="nav-number">12.3.</span> <span class="nav-text">小结</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#ddl%E6%9F%A5%E7%9C%8B%E8%A1%A8"><span class="nav-number">13.</span> <span class="nav-text">13、DDL查看表</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%9B%AE%E6%A0%87-10"><span class="nav-number">13.1.</span> <span class="nav-text">目标</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%AE%B2%E8%A7%A3-10"><span class="nav-number">13.2.</span> <span class="nav-text">讲解</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%B0%8F%E7%BB%93-9"><span class="nav-number">13.3.</span> <span class="nav-text">小结</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#ddl%E5%88%A0%E9%99%A4%E8%A1%A8"><span class="nav-number">14.</span> <span class="nav-text">14、DDL删除表</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%9B%AE%E6%A0%87-11"><span class="nav-number">14.1.</span> <span class="nav-text">目标</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%AE%B2%E8%A7%A3-11"><span class="nav-number">14.2.</span> <span class="nav-text">讲解</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%BF%AB%E9%80%9F%E5%88%9B%E5%BB%BA%E4%B8%80%E4%B8%AA%E8%A1%A8%E7%BB%93%E6%9E%84%E7%9B%B8%E5%90%8C%E7%9A%84%E8%A1%A8"><span class="nav-number">14.2.1.</span> <span class="nav-text">快速创建一个表结构相同的表</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%88%A0%E9%99%A4%E8%A1%A8"><span class="nav-number">14.2.2.</span> <span class="nav-text">删除表</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%B0%8F%E7%BB%93-10"><span class="nav-number">14.3.</span> <span class="nav-text">小结</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#ddl%E4%BF%AE%E6%94%B9%E8%A1%A8%E7%BB%93%E6%9E%84%E4%BA%86%E8%A7%A3"><span class="nav-number">15.</span> <span class="nav-text">15、DDL修改表结构(了解)</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%9B%AE%E6%A0%87-12"><span class="nav-number">15.1.</span> <span class="nav-text">目标</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%AE%B2%E8%A7%A3-12"><span class="nav-number">15.2.</span> <span class="nav-text">讲解</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%B0%8F%E7%BB%93-11"><span class="nav-number">15.3.</span> <span class="nav-text">小结</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#dml%E6%8F%92%E5%85%A5%E8%AE%B0%E5%BD%95%E9%87%8D%E7%82%B9"><span class="nav-number">16.</span> <span class="nav-text">16、DML插入记录(重点)</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%9B%AE%E6%A0%87-13"><span class="nav-number">16.1.</span> <span class="nav-text">目标</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%AE%B2%E8%A7%A3-13"><span class="nav-number">16.2.</span> <span class="nav-text">讲解</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#%E6%8F%92%E5%85%A5%E5%85%A8%E9%83%A8%E5%AD%97%E6%AE%B5"><span class="nav-number">16.2.1.</span> <span class="nav-text">插入全部字段</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E6%8F%92%E5%85%A5%E9%83%A8%E5%88%86%E6%95%B0%E6%8D%AE"><span class="nav-number">16.2.2.</span> <span class="nav-text">插入部分数据</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E6%89%B9%E9%87%8F%E6%8F%92%E5%85%A5%E6%95%B0%E6%8D%AE"><span class="nav-number">16.2.3.</span> <span class="nav-text">批量插入数据</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E6%B3%A8%E6%84%8F"><span class="nav-number">16.2.4.</span> <span class="nav-text">注意</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%B0%8F%E7%BB%93-12"><span class="nav-number">16.3.</span> <span class="nav-text">小结</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#dml%E6%9B%B4%E6%96%B0%E8%A1%A8%E8%AE%B0%E5%BD%95"><span class="nav-number">17.</span> <span class="nav-text">17、DML更新表记录</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%9B%AE%E6%A0%87-14"><span class="nav-number">17.1.</span> <span class="nav-text">目标</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%AE%B2%E8%A7%A3-14"><span class="nav-number">17.2.</span> <span class="nav-text">讲解</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%B0%8F%E7%BB%93-13"><span class="nav-number">17.3.</span> <span class="nav-text">小结</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#dml%E5%88%A0%E9%99%A4%E8%A1%A8%E8%AE%B0%E5%BD%95"><span class="nav-number">18.</span> <span class="nav-text">18、DML删除表记录</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%9B%AE%E6%A0%87-15"><span class="nav-number">18.1.</span> <span class="nav-text">目标</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%AE%B2%E8%A7%A3-15"><span class="nav-number">18.2.</span> <span class="nav-text">讲解</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%B0%8F%E7%BB%93-14"><span class="nav-number">18.3.</span> <span class="nav-text">小结</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#dql%E6%B2%A1%E6%9C%89%E6%9D%A1%E4%BB%B6%E7%9A%84%E7%AE%80%E5%8D%95%E6%9F%A5%E8%AF%A2"><span class="nav-number">19.</span> <span class="nav-text">19、DQL没有条件的简单查询</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%9B%AE%E6%A0%87-16"><span class="nav-number">19.1.</span> <span class="nav-text">目标</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%AE%B2%E8%A7%A3-16"><span class="nav-number">19.2.</span> <span class="nav-text">讲解</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#%E6%9F%A5%E8%AF%A2%E8%A1%A8%E4%B8%AD%E6%8C%87%E5%AE%9A%E5%88%97%E6%95%B0%E6%8D%AE"><span class="nav-number">19.2.1.</span> <span class="nav-text">查询表中指定列数据</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%88%AB%E5%90%8D%E6%9F%A5%E8%AF%A2"><span class="nav-number">19.2.2.</span> <span class="nav-text">别名查询</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E6%B8%85%E9%99%A4%E9%87%8D%E5%A4%8D%E5%80%BC"><span class="nav-number">19.2.3.</span> <span class="nav-text">清除重复值</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E6%9F%A5%E8%AF%A2%E7%BB%93%E6%9E%9C%E5%8F%82%E4%B8%8E%E8%BF%90%E7%AE%97"><span class="nav-number">19.2.4.</span> <span class="nav-text">查询结果参与运算</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%B0%8F%E7%BB%93-15"><span class="nav-number">19.3.</span> <span class="nav-text">小结</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E8%A0%95%E8%99%AB%E5%A4%8D%E5%88%B6%E4%BA%86%E8%A7%A3%E8%AF%BE%E4%B8%8A%E4%B8%8D%E8%AE%B2%E8%A7%A3"><span class="nav-number">20.</span> <span class="nav-text">20、蠕虫复制(了解，课上不讲解)</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%9B%AE%E6%A0%87-17"><span class="nav-number">20.1.</span> <span class="nav-text">目标</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%AE%B2%E8%A7%A3-17"><span class="nav-number">20.2.</span> <span class="nav-text">讲解</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#dql%E6%9F%A5%E8%AF%A2%E8%AF%AD%E5%8F%A5-%E6%9D%A1%E4%BB%B6%E6%9F%A5%E8%AF%A2%E6%8E%8C%E6%8F%A1"><span class="nav-number">21.</span> <span class="nav-text">21、DQL查询语句-条件查询(掌握)</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%9B%AE%E6%A0%87-18"><span class="nav-number">21.1.</span> <span class="nav-text">目标</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%AE%B2%E8%A7%A3-18"><span class="nav-number">21.2.</span> <span class="nav-text">讲解</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%87%86%E5%A4%87%E6%95%B0%E6%8D%AE"><span class="nav-number">21.2.1.</span> <span class="nav-text">准备数据</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E6%AF%94%E8%BE%83%E8%BF%90%E7%AE%97%E7%AC%A6"><span class="nav-number">21.2.2.</span> <span class="nav-text">比较运算符</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E9%80%BB%E8%BE%91%E8%BF%90%E7%AE%97%E7%AC%A6"><span class="nav-number">21.2.3.</span> <span class="nav-text">逻辑运算符</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E8%8C%83%E5%9B%B4"><span class="nav-number">21.2.4.</span> <span class="nav-text">范围</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%A8%A1%E7%B3%8A%E6%9F%A5%E8%AF%A2like%E6%8E%8C%E6%8F%A1"><span class="nav-number">22.</span> <span class="nav-text">22、模糊查询like(掌握)</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%9B%AE%E6%A0%87-19"><span class="nav-number">22.1.</span> <span class="nav-text">目标</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%AE%B2%E8%A7%A3-19"><span class="nav-number">22.2.</span> <span class="nav-text">讲解</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%B0%8F%E7%BB%93-16"><span class="nav-number">22.3.</span> <span class="nav-text">小结</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#dql%E6%9F%A5%E8%AF%A2%E8%AF%AD%E5%8F%A5-%E6%8E%92%E5%BA%8F%E6%8E%8C%E6%8F%A1"><span class="nav-number">23.</span> <span class="nav-text">23、DQL查询语句-排序(掌握)</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%9B%AE%E6%A0%87-20"><span class="nav-number">23.1.</span> <span class="nav-text">目标</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%AE%B2%E8%A7%A3-20"><span class="nav-number">23.2.</span> <span class="nav-text">讲解</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%B0%8F%E7%BB%93-17"><span class="nav-number">23.3.</span> <span class="nav-text">小结</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#dql%E6%9F%A5%E8%AF%A2%E8%AF%AD%E5%8F%A5-%E8%81%9A%E5%90%88%E5%87%BD%E6%95%B0%E6%8E%8C%E6%8F%A1"><span class="nav-number">24.</span> <span class="nav-text">24、DQL查询语句-聚合函数(掌握)</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%9B%AE%E6%A0%87-21"><span class="nav-number">24.1.</span> <span class="nav-text">目标</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%AE%B2%E8%A7%A3-21"><span class="nav-number">24.2.</span> <span class="nav-text">讲解</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%B0%8F%E7%BB%93-18"><span class="nav-number">24.3.</span> <span class="nav-text">小结</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#dql%E6%9F%A5%E8%AF%A2%E8%AF%AD%E5%8F%A5-%E5%88%86%E7%BB%84%E6%8E%8C%E6%8F%A1"><span class="nav-number">25.</span> <span class="nav-text">25、DQL查询语句-分组(掌握)</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%9B%AE%E6%A0%87-22"><span class="nav-number">25.1.</span> <span class="nav-text">目标</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%AE%B2%E8%A7%A3-22"><span class="nav-number">25.2.</span> <span class="nav-text">讲解</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%B0%8F%E7%BB%93-19"><span class="nav-number">25.3.</span> <span class="nav-text">小结</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%80%BB%E7%BB%93"><span class="nav-number">26.</span> <span class="nav-text">总结</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%BD%9C%E4%B8%9A"><span class="nav-number"></span> <span class="nav-text">作业:</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E4%BD%9C%E4%B8%9A1%E5%AE%9E%E6%93%8D%E9%A2%98"><span class="nav-number">1.</span> <span class="nav-text">作业1:实操题</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E4%BD%9C%E4%B8%9A2sql%E9%A2%98"><span class="nav-number">2.</span> <span class="nav-text">作业2:sql题</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E4%BD%9C%E4%B8%9A3"><span class="nav-number">3.</span> <span class="nav-text">作业3:</span></a></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="Ethan Liu"
      src="/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">Ethan Liu</p>
  <div class="site-description" itemprop="description"><font color='#0000FF' size=1.5px>语言学 | NLP | Py | Java</font></div>
</div>
<div class="site-state-wrap animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">53</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/categories/">
        <span class="site-state-item-count">14</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
          <a href="/tags/">
        <span class="site-state-item-count">18</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author animated">
      <span class="links-of-author-item">
        <span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL2V0aGFubGl1Ng==" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;ethanliu6"><i class="fab fa-github fa-fw"></i>GitHub</span>
      </span>
      <span class="links-of-author-item">
        <span class="exturl" data-url="bWFpbHRvOmxpdWUyMzM2QGdtYWlsLmNvbQ==" title="E-Mail → mailto:liue2336@gmail.com"><i class="fa fa-envelope fa-fw"></i>E-Mail</span>
      </span>
      <span class="links-of-author-item">
        <span class="exturl" data-url="aHR0cHM6Ly9zcGFjZS5iaWxpYmlsaS5jb20vMTMyNzA5OTk3Nw==" title="BiliBili → https:&#x2F;&#x2F;space.bilibili.com&#x2F;1327099977"><i class="fa-brands fa-bilibili fa-fw"></i>BiliBili</span>
      </span>
      <span class="links-of-author-item">
        <a href="/categories/Love/" title="Love → &#x2F;categories&#x2F;Love&#x2F;" rel="noopener me"><i class="fa fa-heart fa-fw"></i>Love</a>
      </span>
  </div>

        </div>
      </div>
    </div>

    
  </aside>


    </div>

    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="Ethan Liu">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="<font color='white' >Ethan の Blog</font>">
      <meta itemprop="description" content="<font color='#0000FF' size=1.5px>语言学 | NLP | Py | Java</font>">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="MYSQL基础语法（上） | <font color='white' >Ethan の Blog</font>">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          MYSQL基础语法（上）<span class="exturl post-edit-link" data-url="aHR0cHM6Ly9naXRodWIuY29tL0V0aGFuTGl1Ni9ldGhhbmxpdTYuZ2l0aHViLmlvL3RyZWUvbWFzdGVyL19wb3N0cy9KYXZhTm90ZXMvTXlTUUwvZGF5MDEvZGF5MDEtTXlTUUzln7rnoYDnrJTorrAubWQ=" title="编辑"><i class="fa fa-pen-nib"></i></span>
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2024-04-30 00:00:00" itemprop="dateCreated datePublished" datetime="2024-04-30T00:00:00+08:00">2024-04-30</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar-check"></i>
      </span>
      <span class="post-meta-item-text">更新于</span>
      <time title="修改时间：2024-05-06 01:48:46" itemprop="dateModified" datetime="2024-05-06T01:48:46+08:00">2024-05-06</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/MySQL/" itemprop="url" rel="index"><span itemprop="name">MySQL</span></a>
        </span>
    </span>

  
    <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv">
      <span class="post-meta-item-icon">
        <i class="far fa-eye"></i>
      </span>
      <span class="post-meta-item-text">阅读次数：</span>
      <span id="busuanzi_value_page_pv"></span>
    </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="far fa-comment"></i>
      </span>
      <span class="post-meta-item-text">Changyan：</span>
    
    <a title="MYSQL基础语法（上）" href="/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/#SOHUCS" itemprop="discussionUrl">
      <span id="sourceId::05a613935fb775621fcd262ee62939dc" class="cy_cmt_count" itemprop="commentCount"></span>
    </a>
  </span>
  
  
    <span class="post-meta-break"></span>
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>10k</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>37 分钟</span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody"><blockquote class="blockquote-center">
<p>这是一篇关于MYSQL基础语法（上）</p>

</blockquote>
<span id="more"></span>
<h2 id="学习目标">学习目标</h2>
<ol type="1">
<li>能够理解数据库的概念</li>
<li>能够安装MySQL数据库</li>
<li>能够启动,关闭及登录MySQL</li>
<li>能够使用SQL语句操作数据库</li>
<li>能够使用SQL语句操作表结构</li>
<li>能够使用SQL语句进行数据的添加修改和删除的操作(掌握)</li>
<li>能够使用SQL语句简单查询数据(掌握)</li>
</ol>
<h2 id="今日重点">今日重点</h2>
<figure class="highlight markdown"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="section">#1.DML 对数据的增删改</span></span><br><span class="line"><span class="section">#2.DQL 对数据的单表查询</span></span><br></pre></td></tr></table></figure>
<h2 id="数据库连接失败">数据库连接失败</h2>
<p>1.查看是否启动mysql服务器：电脑---管理---服务--mysql,安装失败的兄弟们使用锁哥的绿色版本，没有密码</p>
<p>2.环境变量配置：D:放到path下面。</p>
<h2 id="连接数据库命令">连接数据库命令</h2>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">mysql <span class="operator">-</span>u root <span class="operator">-</span>p</span><br><span class="line"><span class="number">1.</span>mysql表示客户端命令，在mysql安装目录的bin目录下：mysql.exe</span><br><span class="line"><span class="number">2.</span><span class="operator">-</span>u:<span class="keyword">user</span> 表示用户 root 表示超级管理员，开发中我们都是普通用户 u1 u2...</span><br><span class="line"><span class="number">3.</span><span class="operator">-</span>p :password 密码</span><br><span class="line"><span class="number">4.</span>注意：mysql命令必须在mysql外部输入</span><br><span class="line"><span class="number">5.</span>mysql <span class="operator">-</span>uroot <span class="operator">-</span>p1234 也可以</span><br><span class="line"><span class="number">6.</span>命令mysql <span class="operator">-</span>u root <span class="operator">-</span>p和mysql <span class="operator">-</span>uroot <span class="operator">-</span>p1234只能连接本地的mysql服务器，如果想远程连接：</span><br><span class="line">	mysql [<span class="operator">-</span>h <span class="number">127.0</span><span class="number">.0</span><span class="number">.1</span> <span class="operator">-</span>P <span class="number">3306</span>] <span class="operator">-</span>uroot <span class="operator">-</span>p1234  </span><br><span class="line">	h：host 连接服务器的ip地址</span><br><span class="line">	P:port 端口号</span><br></pre></td></tr></table></figure>
<h1 id="学习内容">学习内容</h1>
<h2 id="数据库的基本知识">1.数据库的基本知识</h2>
<h3 id="目标">目标</h3>
<ol type="1">
<li>能够掌握数据库的概念</li>
<li>能够说出常用的数据库</li>
</ol>
<h3 id="讲解">讲解</h3>
<h4 id="什么是数据库">什么是数据库</h4>
<p>保存数据的仓库。它体现我们电脑中，就是一个软件或者文件系统。然后把数据都保存这些特殊的文件中，并且需要使用固定的语言（<strong>SQL语言/语句</strong>）去操作文件中的数据。</p>
<h3 id="数据的存储方式">数据的存储方式</h3>
<p>需求：开发一个学生选课系统，学生系统中含有学生信息、老师信息、课程信息。需要将关系和数据进行保存，保存到哪里合适呢？</p>
<ol type="1">
<li><p><strong>数据保存在内存</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">Student</span> <span class="variable">s</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">Student</span>(<span class="string">&quot;张三&quot;</span>,<span class="number">18</span>,<span class="string">&quot;上海&quot;</span>);</span><br><span class="line"><span class="type">Teacher</span> <span class="variable">t</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">Teacher</span>(<span class="string">&quot;锁哥&quot;</span>,<span class="number">19</span>,<span class="string">&quot;上海&quot;</span>);</span><br><span class="line"><span class="type">Course</span> <span class="variable">c</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">Course</span>(<span class="string">&quot;语文&quot;</span>,<span class="number">90</span>);</span><br></pre></td></tr></table></figure>
<p>new出来的对象存储在堆中.堆是内存中的一小块空间</p>
<p>优点：存储速度快 缺点：断电/程序退出,数据就清除了</p></li>
<li><p><strong>数据使用IO流技术保存在硬盘的普通文件中</strong>
优点：永久保存
缺点：IO流的查找，增加，修改，删除数据比较麻烦。同时使用IO流技术需要频繁调用系统资源和将系统资源还给系统，这样操作效率比较低</p></li>
<li><p><strong>数据保存在数据库</strong>
优点：永久保存,通过SQL语句比较方便的操作数据库。是方式一和方式二的结合。可以解决上述两种方式的缺点。</p></li>
</ol>
<h4 id="数据库的优点">数据库的优点</h4>
<p>​
数据库是按照特定的格式将数据存储在文件中，通过SQL语句可以方便的对大量数据进行增、删、改、查操作，数据库是对大量的信息进行管理的高效的解决方案。</p>
<h4 id="常见数据库">常见数据库</h4>
<p>​
我们开发应用程序的时候，程序中的所有数据，最后都需要保存到专业软件中。这些专业的保存数据的软件我们称为数据库。我们学习数据库，并不是学习如何去开发一个数据库软件，我们学习的是如何使用数据库以及数据库中的数据记录的操作。而数据库软件是由第三方公司研发。</p>
<p><strong>Oracle</strong>：它是Oracle公司的大型关系型数据库。系统可移植性好、使用方便、功能强，适用于各类大、中、小、微机环境。它是一种高效率、安全可靠的。但是它是收费的。
<strong>MYSQL</strong>：早期由瑞典一个叫MySQL
AB公司开发的，后期被sun公司收购，再后期被Oracle收购。体积小、速度快、总体拥有成本低，尤其是<span class="exturl" data-url="aHR0cHM6Ly9iYWlrZS5iYWlkdS5jb20vaXRlbS8lRTUlQkMlODAlRTYlOTQlQkUlRTYlQkElOTAlRTclQTAlODE=">开放源码<i class="fa fa-external-link-alt"></i></span>这一特点，一般中小型网站的开发都选择
MySQL 作为网站数据库。MySQL6.x版本也开始收费。 <strong>DB2</strong>
：IBM公司的数据库产品,收费的。常应用在银行系统中.
<strong>SQLServer</strong>：MicroSoft
公司收费的中型的数据库。C#、.net等语言常使用。
<strong>SyBase</strong>：Sybase公司的。
已经淡出历史舞台。提供了一个非常专业数据建模的工具PowerDesigner。</p>
<p><strong>常用数据库</strong>：Java开发应用程序主要使用的数据库：MySQL（5.6）、Oracle、DB2。
在web应用中，使用的最多的就是MySQL数据库，原因如下：</p>
<ol type="1">
<li>开源、免费</li>
<li>功能足够强大，足以应付web应用开发（最高支持千万级别的并发访问）</li>
</ol>
<h3 id="小结">小结</h3>
<ol type="1">
<li>说出数据库的概念：存储数据的仓库</li>
<li>说出常用的数据库：MYSQL, Oracle,DB2</li>
</ol>
<h2 id="关系型数据库">2.关系型数据库</h2>
<p>在开发软件的时候，软件中的数据之间必然会有一定的关系存在。比如商品和客户之间的关系，一个客户是可以买多种商品，而一种商品是可以被多个客户来购买的。</p>
<p>需要把这些数据保存在数据库中，同时也要维护数据之间的关系，这时就可以直接使用上述的那些数据库。而上述的所有数据库都属于关系型数据库。</p>
<p>关系型数据：设计数据库的时候，需要使用E-R实体关系图来描述。</p>
<p>E-R 是两个单词的首字母，E表示Entity 实体 R表示Relationship 关系。</p>
<p>实体：可以理解成我们Java程序中的一个对象。比如商品，客户等都是一个实体对象。在E-R图中使用
矩形(长方形) 表示。</p>
<p>属性：实体对象中是含有属性的，比如商品名、价格等。针对一个实体中的属性，我们称为这个实体的数据，在E-R图中使用椭圆表示。</p>
<p>关系：实体和实体之间的关系：在E-R图中使用菱形表示。</p>
<p>需求： 使用E-R图描述 客户、商品、订单之间的关系。</p>
<p><img data-src="img/关系型数据库图解.bmp"></p>
<h2 id="数据库的安装">3.数据库的安装</h2>
<h3 id="目标-1">目标</h3>
<p>能够安装mysql数据库软件</p>
<h3 id="讲解-1">讲解</h3>
<p>安装过程：</p>
<p>1．在今天的资料下有Mysql的安装包,找到如下所示文件后双击</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mysql-installer-community-5.6.22.0.msi</span><br></pre></td></tr></table></figure>
<p>2.双击之后会出现如下图所示界面，询问是否同意，将我同意的选框勾选上，然后点击next,如下：</p>
<p><img data-src="img/mysql安装图解1.bmp"></p>
<p>3.选择自定义安装,点击下一步</p>
<p><img data-src="img/mysql安装图解2.bmp"></p>
<p>4.根据电脑配置选择要安装的MySql版本,然后点击next</p>
<p><img data-src="img/mysql安装图解3.bmp"></p>
<p><img data-src="img/mysql安装图解4.bmp"></p>
<p>5.如果出现当前界面,则可以配置安装目录,如果出现的不是这个界面请点击Back返回</p>
<p><img data-src="img/mysql安装图解5.bmp"></p>
<p>6.点击back返回后,点击高级选项,配置安装路径,配置成功后点击下一步</p>
<p><img data-src="img/mysql安装图解6.bmp"></p>
<p><img data-src="img/mysql安装图解7.bmp"></p>
<p>说明：安装路径最好不要有中文和空格以及特殊符号。</p>
<p>注意：一定要保证Install Directory和data
Directory保存的路径一致，这样才可以保证卸载MySql的时候会很方便。</p>
<p><img data-src="img/mysql安装图解8.bmp"></p>
<p>7.当出现绿色对号时表名安装成功,然后点击下一步</p>
<p><img data-src="img/mysql安装图解9.bmp"></p>
<p>8.开始配置mysql,点击下一步</p>
<p><img data-src="img/mysql安装图解10.bmp"></p>
<p>9.配置MySql开发模式以及端口号相关配置,然后点击下一步</p>
<p><img data-src="img/mysql安装图解11.bmp"></p>
<p>说明：MySql默认端口是3306.这里不要修改，我们访问数据库的时候输入端口号3306即可。</p>
<p>10.设置密码账户信息,然后点击next</p>
<p><img data-src="img/mysql安装图解12.bmp"></p>
<p>11.使用默认配置就可以了,然后点击下一步</p>
<p><img data-src="img/mysql安装图解13.bmp"></p>
<p>12.日志配置</p>
<p><img data-src="img/mysql安装图解14.bmp"></p>
<p>13.点击Execute安装</p>
<p><img data-src="img/mysql安装图解15.bmp"></p>
<p>14.全部画上绿色对勾之后,安装成功点击finish-&gt;next-&gt;finish</p>
<p><img data-src="img/mysql安装图解16.bmp"></p>
<p><img data-src="img/mysql安装图解17.bmp"></p>
<p><img data-src="img/mysql安装图解18.bmp"></p>
<p>15.配置环境变量,找到MySql的安装目录的bin目录下,将路径复制下来</p>
<p><img data-src="img/mysql安装图解19.bmp"></p>
<p>16.打开电脑的高级设置中的 path 路径,将复制的路径添加进去</p>
<p><img data-src="img/mysql安装图解20.bmp"></p>
<h3 id="小结-1">小结</h3>
<ol type="1">
<li>MySQL安装过程的步骤： 按照上述一步一步安装即可</li>
<li>MySQL端口号是：3306</li>
<li>管理员名字：root</li>
<li>将mysql的bin目录配置到path环境变量中</li>
</ol>
<h2 id="命令行客户端连接服务器测试是否安装成功">4.命令行客户端连接服务器(测试是否安装成功)</h2>
<h3 id="目标-2">目标</h3>
<ol type="1">
<li>能够打开和关闭mysql服务</li>
<li>能够连接到mysql</li>
</ol>
<h3 id="讲解-2">讲解</h3>
<p><strong>1、打开和关闭mysql服务.</strong></p>
<p>查看windows服务 ，mysql数据库是否启动。</p>
<p><img data-src="img/1550408825267.png" alt="1550408825267"> <img data-src="img/mysql启动02.png" alt="mysql启动02"></p>
<p><strong>2、连接mysql</strong></p>
<figure>
<img data-src="img/1550409365086.png" alt="1550289380140">
<figcaption aria-hidden="true">1550289380140</figcaption>
</figure>
<p>​
MySQL是一个需要账户名密码登录的数据库，登陆后使用，它提供了一个默认的root账号，使用安装时设置的密码即可登录
1. 登录格式1：<code>mysql -u用户名 -p密码</code> 例如：</p>
<p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mysql <span class="operator">-</span>uroot <span class="operator">-</span>p1234</span><br></pre></td></tr></table></figure></p>
<p>在打开的dos窗口中输入mysql -uroot -p命令：</p>
<p><img data-src="img/测试mysql是否连接成功2.PNG" alt="MYSQL登录01">
后输入密码方式：</p>
<p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">mysql <span class="operator">-</span>u root <span class="operator">-</span>p</span><br><span class="line">下一行输入密码</span><br></pre></td></tr></table></figure></p>
<figure>
<img data-src="img/dos窗口测试是否连接成功.PNG" alt="MYSQL登录04">
<figcaption aria-hidden="true">MYSQL登录04</figcaption>
</figure>
<ol start="2" type="1">
<li><p>登录格式2：</p>
<p><strong>mysql</strong> <strong>[<strong>-h 连接的主机ip
-P端口3306</strong>]</strong> <strong>-u 用户名 -p 密码</strong></p>
<p>例如：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mysql <span class="operator">-</span>h <span class="number">192.168</span><span class="number">.1</span><span class="number">.251</span> <span class="operator">-</span>P <span class="number">3306</span> <span class="operator">-</span>u root <span class="operator">-</span>p <span class="number">1234</span> </span><br></pre></td></tr></table></figure>
<p>​ 如果连接的是本机：可以省略 -h -P
主机IP和端口。这样就可以登录mysql数据库了。</p></li>
<li><p>退出MySQL：<code>exit</code> <img data-src="img/测试mysql是否连接成功2.PNG" alt="MYSQL登录03"></p></li>
</ol>
<h3 id="小结-2">小结</h3>
<ol type="1">
<li>打开和关闭mysql服务？</li>
<li>连接到本机的mysql？mysql -uroot -p1234</li>
<li>连接到指定主机的mysql？ <strong>mysql</strong> <strong>[<strong>-h
连接的主机ip -P端口3306</strong>]</strong> <strong>-u 用户名 -p
密码</strong></li>
</ol>
<h2 id="图形界面datagrip客户端">5、图形界面DataGrip客户端</h2>
<h3 id="目标-3">目标</h3>
<ol type="1">
<li>能够掌握DataGrip的安装</li>
<li>能够使用DataGrip连接mysql数据库</li>
</ol>
<h3 id="讲解-3">讲解</h3>
<figure>
<img data-src="img/1550409365086.png" alt="1550289366973">
<figcaption aria-hidden="true">1550289366973</figcaption>
</figure>
<p>​
在dos窗口中使用sql语句操作mysql数据库相对来说，太麻烦了，我们在实际开发中不会使用dos窗口来操作的，一定要使用可视化工具来操作mysql数据库，而会有多种可视化工具来操作mysql数据库，比如：Navicat、SQLyog、DataGrip等。我们这里使用DataGrip可视化工具。</p>
<p><font color="red" size="7px">补充：参考 03_资料.md
文档进行安装和使用</font></p>
<h3 id="小结-3">小结</h3>
<ol start="2" type="1">
<li>使用DataGrip连接mysql? 在链接界面输入数据账号,密码,端口号</li>
<li>如果ip地址是localhost连接不上数据库，可以使用127.0.0.1尝试</li>
</ol>
<h2 id="卸载">6、卸载</h2>
<p>1、找到mysql的安装目录：在mysql的安装目录中。找到my.ini 文件。</p>
<figure>
<img data-src="img\image-20200609100334374.png" alt="image-20200609100334374">
<figcaption aria-hidden="true">image-20200609100334374</figcaption>
</figure>
<p>找到datadir 并且记录路径。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">datadir=&quot;D:/MySoft/MySql2/data/Data/&quot;</span><br></pre></td></tr></table></figure>
<p>说明：</p>
<p>​
1）datadir路径是用来保存mysql的数据文件的目录，以后我们向Mysql数据库存储的数据都会存放到这个路径；</p>
<p>​
2）在安装数据库的时候，要求这个路径的下的data文件夹要和数据库在同一文件夹下，这样在卸载的时候会比较方便，直接删除即可。如果没有安装到同一目录，那么找到该data文件夹进行删除；</p>
<p>2、在电脑左下角window图标处-----》右键----》选择控制面板；</p>
<p>3、找到程序和功能；</p>
<p>4、找到Mysql----&gt;卸载mysql</p>
<p>5、删除mysql的安装目录，删除mysql的数据文件目录datadir.第一步中记录的文件目录。</p>
<p>注意：mysql默认的数据文件目录，在ProgramData这个目录下，并且ProgramData这个目录是隐藏目录，需要设置显示隐藏目录。</p>
<p>删除ProgramData下的mysql的相关目录。</p>
<p>6、打开运行窗口-----》输入regedit----》打开注册表-----》删除</p>
<p>HKEY_LOCAL_MACHINE</p>
<p>注意：一般情况下执行前5步即可，如果还不能安装，就执行步骤6，运行regedit,试着删除注册表中的数据，或者也可以使用360或者安全管家清理垃圾试试。</p>
<h2 id="服务器与数据库表记录的关系">7、服务器与数据库、表、记录的关系</h2>
<h3 id="目标-4">目标</h3>
<p>能够理解mysql服务器与数据库、表、记录的关系</p>
<h3 id="讲解-4">讲解</h3>
<figure>
<img data-src="img/1550409365086.png" alt="1550409365086">
<figcaption aria-hidden="true">1550409365086</figcaption>
</figure>
<h4 id="实体类与表的对应关系">实体类与表的对应关系</h4>
<figure>
<img data-src="img/%E5%AE%9E%E4%BD%93%E7%B1%BB%E4%B8%8E%E8%A1%A8%E7%9A%84%E5%AF%B9%E5%BA%94%E5%85%B3%E7%B3%BB.png" alt="实体类与表的对应关系">
<figcaption aria-hidden="true">实体类与表的对应关系</figcaption>
</figure>
<p><img data-src="img/数据库内部存储结构.PNG"></p>
<p>说明：</p>
<p>1、一个数据库软件可以安装多个数据仓库，数据仓库可以简称为数据库，在数据库中创建数据表来保存数据。</p>
<p>2、数据库的一行称为记录，可以理解成java实例化后的一个对象。</p>
<p>3、数据库的一列称为字段，理解成java类中的属性。</p>
<p>4、一个数据仓库中是可以有多张表的。</p>
<p>未来关于数据库我们学习的目标：</p>
<p>1）对数据库进行增删改查(CRUD);(主要对整个数据库进行操作，比如删除一个数据库和增加一个数据库)。create(增)
read(查) update(改) delete(删)</p>
<p>2）对数据表结构进行增删改查(CRUD);(主要对整张表，比如删除一张表和增加一张表)。</p>
<p>3）<strong>对表中的数据进行增删改查(CRUD);(主要对表中的具体数据，比如删除一个表中的一行记录和增加一行数据)。</strong></p>
<p>注意：关于对数据库表的操作，查询是开发中最难的，也是最重要的；</p>
<h3 id="小结-4">小结</h3>
<p>一个数据库软件，可以管理多个数据仓库（数据库）。</p>
<p>一个数据仓库可以管理多张数据表。</p>
<p>每个数据表中可以存储多行数据记录。</p>
<p>提示：每创建一个数据仓库，会在mysql的数据文件目录(data)中多一个文件夹。</p>
<h2 id="sql语句的分类和语法">8、SQL语句的分类和语法</h2>
<h3 id="目标-5">目标</h3>
<ol type="1">
<li>能够掌握SQL的概念和作用</li>
</ol>
<h3 id="讲解-5">讲解</h3>
<h4 id="什么是sql">什么是SQL</h4>
<p>Structured Query
Language结构化查询语言。SQL语句不依赖于任何平台，对所有的数据库是通用的。学会了SQL语句的使用，可以在任何的数据库使用,但都有特有内容。SQL语句功能强大、<span class="exturl" data-url="aHR0cDovL2JhaWtlLmJhaWR1LmNvbS9zdWJ2aWV3LzY2NTQzLzUwOTQ5NTguaHRt">简单<i class="fa fa-external-link-alt"></i></span>易学、使用方便。</p>
<h4 id="sql特点">SQL特点</h4>
<p>SQL语句是一个非过程性的语言，每一条SQL执行完都会有一个具体的结果出现。多条语句之间没有影响。</p>
<p>过程性语言：例如java。</p>
<p>int a = 10;</p>
<p>int b = 20;</p>
<p>int sum = a +b;</p>
<h4 id="sql作用">SQL作用</h4>
<p>SQL语句主要是操作数据库，数据表，<strong>数据表中的数据记录</strong>。</p>
<h4 id="sql语句分类">SQL语句分类</h4>
<p>SQL是用来存取关系数据库的语言，具有定义、操纵、控制和查询关系型数据库的四方面功能。所以针对四方面功能，我们将SQL进行了分类。</p>
<ol type="1">
<li><p>DDL(Data Definition Language)数据定义语言
用来定义数据库对象：数据库，表，列等。关键字：create drop alter
truncate(清空数据记录) show等</p></li>
<li><p>DML(Data Manipulation Language)数据操作语言★★★</p>
<p>在数据库表中更新，增加和删除记录。如 update(更新)， insert(插入)，
delete(删除) 不包含查询</p></li>
<li><p>DQL(Data Query Language) 数据查询语言★★★★★
数据表记录的查询。关键字select。</p></li>
<li><p>DCL(<strong>Data Control Language</strong>)数据控制语言(了解)</p>
<p>是用来设置或更改数据库用户或角色权限的语句，如grant(设置权限)，revoke(撤销权限)，begin
transaction等。这个比较少用到。</p></li>
</ol>
<h4 id="sql学习方向">SQL学习方向</h4>
<p>我们学习SQL语句的路线：</p>
<p>1、学习SQL数据对数据库的操作；</p>
<p>2、学习SQL语句对数据表整体结构的操作；</p>
<p>3、学习SQL语句对数据表中的数据记录操作(★★★★★)；</p>
<p>4、数据仓库中的数据备份和恢复；</p>
<h4 id="sql通用语法">SQL通用语法</h4>
<ol type="1">
<li><p>SQL语句可以单行或多行书写，以分号结尾。</p></li>
<li><p>可使用空格和缩进来增强语句的可读性。</p></li>
<li><p>MySQL数据库的SQL语句不区分大小写，关键字开发中一般大写。
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> <span class="operator">*</span> <span class="keyword">FROM</span> student;</span><br></pre></td></tr></table></figure></p></li>
<li><p>3种注释 单行注释: -- 注释内容 多行注释: /* 注释 */</p>
<p><strong>#</strong> 注释内容(mysql特有的单行注释) ### 小结</p></li>
<li><p>SQL的作用？对数据库进行操作的语句,增删改查</p></li>
<li><p>SQL的分类？ DDL:操作数据和表 DML:对表中的记录进行增删改
DQL:对表中的记录进行查询</p></li>
<li><p>SQL的语法特点？ 可以写一行,也可以写成多行,最好是以;结尾
关键字建议大写 可以任意缩进 单行注释: -- 开头 # 开头 多行注释: /*
*/</p></li>
</ol>
<h2 id="ddl创建数据库">9、DDL创建数据库</h2>
<h3 id="目标-6">目标</h3>
<p>能够掌握创建数据库的三种语法</p>
<h3 id="讲解-6">讲解</h3>
<h4 id="创建数据库">创建数据库</h4>
<ol type="1">
<li><p>直接创建数据库</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">CREATE</span> DATABASE 数据库名;</span><br></pre></td></tr></table></figure></li>
<li><p>判断是否存在并创建数据库</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">CREATE</span> DATABASE IF <span class="keyword">NOT</span> <span class="keyword">EXISTS</span> 数据库名;</span><br></pre></td></tr></table></figure></li>
<li><p>创建数据库并指定字符集(编码表)</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">CREATE</span> DATABASE 数据库名 <span class="type">character</span> <span class="keyword">set</span> 字符集;</span><br><span class="line">说明：字符集就是编码表名。在mysql中utf8 latin1 </span><br></pre></td></tr></table></figure></li>
<li><p>具体操作：</p></li>
</ol>
<ul>
<li><p>直接创建数据库db1 <figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">CREATE</span> DATABASE db1;</span><br></pre></td></tr></table></figure> <img data-src="img/直接创建数据库.png" alt="直接创建数据库"></p></li>
<li><p>判断是否存在并创建数据库db2 <figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">CREATE</span> DATABASE IF <span class="keyword">NOT</span> <span class="keyword">EXISTS</span> db2;</span><br></pre></td></tr></table></figure> <img data-src="img/判断是否存在并创建数据库.png" alt="判断是否存在并创建数据库"></p></li>
<li><p>创建数据库db3并指定字符集为gbk <figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">CREATE</span> DATABASE db2 <span class="type">CHARACTER</span> <span class="keyword">SET</span> gbk;</span><br></pre></td></tr></table></figure> <img data-src="img/创建数据库并指定字符集.png" alt="创建数据库并指定字符集"></p></li>
</ul>
<h4 id="查看数据库">查看数据库</h4>
<ol type="1">
<li>查看所有的数据库 <figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SHOW</span> DATABASES;</span><br></pre></td></tr></table></figure> <img data-src="img/查看所有数据库.png" alt="查看所有数据库"></li>
<li>查看某个数据库的定义信息 <figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SHOW</span> <span class="keyword">CREATE</span> DATABASE 数据库名;</span><br></pre></td></tr></table></figure> <img data-src="img/查看某个数据库的定义信息.png" alt="查看某个数据库的定义信息"></li>
</ol>
<h3 id="小结-5">小结</h3>
<ol type="1">
<li>创建数据库语法：CREATE DATABASE 数据库名;</li>
<li>查看有哪些数据库：SHOW DATABASES;</li>
</ol>
<h2 id="ddl修改和删除数据库">10、DDL修改和删除数据库</h2>
<h3 id="目标-7">目标</h3>
<ol type="1">
<li>能够修改数据库的字符集</li>
<li>能够删除数据库</li>
</ol>
<h3 id="讲解-7">讲解</h3>
<h4 id="修改数据库字符集">修改数据库字符集</h4>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">ALTER</span> 表示修改：</span><br><span class="line"><span class="keyword">ALTER</span> DATABASE 数据库 <span class="keyword">default</span> <span class="type">character</span> <span class="keyword">set</span> 新的字符集;</span><br></pre></td></tr></table></figure>
<p>具体操作： * 将db3数据库的字符集改成utf8 <figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">ALTER</span> DATABASE db3 <span class="keyword">DEFAULT</span> <span class="type">CHARACTER</span> <span class="keyword">SET</span> utf8;</span><br></pre></td></tr></table></figure>
注意：如果修改数据库指定的编码表是utf8,记住不能写utf-8.。utf-8
是错误的</p>
<p>(mysql不认识utf-8)。</p>
<p>java中的常用编码 : UTF-8; GBK;GB2312;ISO-8859-1;</p>
<p>对应mysql数据库中的编码: utf8; gbk;gb2312; latin1;</p>
<p><img data-src="img/修改数据库字符集.png" alt="修改数据库字符集"> ####
删除数据库</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">drop</span> <span class="comment">--表示删除数据库或表</span></span><br><span class="line"><span class="keyword">DROP</span> DATABASE 数据库名;</span><br></pre></td></tr></table></figure>
<p>具体操作： * 删除db2数据库 <figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">DROP</span> DATABASE db2;</span><br></pre></td></tr></table></figure> <img data-src="img/删除数据库.png" alt="删除数据库"></p>
<h3 id="小结-6">小结</h3>
<ol type="1">
<li>修改数据库的字符集格式？alter database 数据库 character set
新的字符集;</li>
<li>删除数据库格式？drop database 数据库名;</li>
</ol>
<h2 id="ddl使用数据库">11、DDL使用数据库</h2>
<h3 id="目标-8">目标</h3>
<ol type="1">
<li>能够掌握切换数据库语法</li>
<li>能够查看正在使用的数据库</li>
</ol>
<h3 id="讲解-8">讲解</h3>
<p>1.查看正在使用的数据库</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> <span class="comment">-- 查询</span></span><br><span class="line"><span class="keyword">SELECT</span> DATABASE();</span><br></pre></td></tr></table></figure>
<p>2.使用/切换数据库</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">USE 数据库名;</span><br></pre></td></tr></table></figure>
<p>具体操作： * 查看正在使用的数据库 <figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> DATABASE();</span><br></pre></td></tr></table></figure> <img data-src="img/查看正在使用的数据库.png" alt="查看正在使用的数据库"> *
使用db1数据库 <figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">USE db1;</span><br></pre></td></tr></table></figure> <img data-src="img/使用db1数据库.png" alt="使用db1数据库"></p>
<h3 id="小结-7">小结</h3>
<table>
<thead>
<tr class="header">
<th>DDL语句操作</th>
<th>关键字</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>创建</td>
<td>create database 数据库名;</td>
</tr>
<tr class="even">
<td>修改</td>
<td>alter database character set 字符集;</td>
</tr>
<tr class="odd">
<td>查看</td>
<td>show databases;</td>
</tr>
<tr class="even">
<td>删除</td>
<td>drop database 数据库名;</td>
</tr>
</tbody>
</table>
<h2 id="ddl创建表">12、DDL创建表</h2>
<h3 id="目标-9">目标</h3>
<ol type="1">
<li>能够掌握SQL创建表</li>
</ol>
<h3 id="讲解-9">讲解</h3>
<blockquote>
<p><strong>前提先使用某个数据库</strong>（db1） #### 创建表
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">CREATE</span> <span class="keyword">TABLE</span> 表名 (字段名<span class="number">1</span> 字段类型<span class="number">1</span>, 字段名<span class="number">2</span> 字段类型<span class="number">2.</span>..);</span><br></pre></td></tr></table></figure></p>
</blockquote>
<p>建议写成如下格式: <figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">javase</span><br><span class="line">public class Student&#123;</span><br><span class="line">	<span class="type">int</span> age;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">CREATE</span> <span class="keyword">TABLE</span> 表名 (</span><br><span class="line">    字段名<span class="number">1</span> 字段类型<span class="number">1</span>, </span><br><span class="line">    字段名<span class="number">2</span> 字段类型<span class="number">2</span></span><br><span class="line">);</span><br><span class="line">最后一个字段不加逗号</span><br></pre></td></tr></table></figure> 关键字说明： <figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">CREATE</span> <span class="comment">-- 表示创建</span></span><br><span class="line"><span class="keyword">TABLE</span> <span class="comment">-- 表示表</span></span><br></pre></td></tr></table></figure> ####
MySQL数据类型</p>
<p>MySQL中的我们常使用的数据类型如下： <img data-src="img/MYSQL常用数据类型.png" alt="MYSQL常用数据类型"></p>
<p>详细的数据类型如下(不建议详细阅读！)</p>
<figure>
<img data-src="img/1550410505421.png" alt="1550410505421">
<figcaption aria-hidden="true">1550410505421</figcaption>
</figure>
<p>具体操作:</p>
<p>创建student表包含id,name,birthday字段</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">CREATE</span> <span class="keyword">TABLE</span> student (</span><br><span class="line">      id <span class="type">INT</span>,</span><br><span class="line">      name <span class="type">VARCHAR</span>(<span class="number">20</span>),</span><br><span class="line">      birthday <span class="type">DATE</span></span><br><span class="line">);</span><br></pre></td></tr></table></figure>
<ul>
<li>需求：设计一张学生表，请注重<strong>数据类型</strong>、<strong>长度的合理性</strong></li>
</ul>
<p>1.编号</p>
<p>2.姓名，姓名最长不超过10个汉字</p>
<p>3.性别，因为取值只有两种可能，因此最多一个汉字</p>
<p>4.生日，取值为年月日</p>
<p>5.入学成绩，小数点后保留两位</p>
<p>6.邮件地址，最大长度不超过 64</p>
<p>7.家庭联系电话，不一定是手机号码，可能会出现 - 等字符</p>
<p>8.学生状态（用数字表示，正常、休学、毕业...）</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">-- 需求1：创建学生表</span></span><br><span class="line"><span class="keyword">create</span> <span class="keyword">table</span> stu(</span><br><span class="line">	<span class="comment">-- 编号</span></span><br><span class="line">	id <span class="type">int</span>,</span><br><span class="line">	name <span class="type">varchar</span>(<span class="number">10</span>), <span class="comment">-- 10表示姓名的值最多只能是10个字符</span></span><br><span class="line">	sex <span class="type">char</span>(<span class="number">1</span>), <span class="comment">-- 1表示性别是1个字符</span></span><br><span class="line">	birthday <span class="type">date</span>,</span><br><span class="line">	score <span class="keyword">double</span>(<span class="number">5</span>,<span class="number">2</span>), <span class="comment">-- 5 表示长度最多是5   2 表示小数点保留2位，即位数 3.14</span></span><br><span class="line">	email <span class="type">varchar</span>(<span class="number">64</span>),</span><br><span class="line">	tel <span class="type">varchar</span>(<span class="number">20</span>),</span><br><span class="line">	<span class="comment">-- 学生状态,tinyint 表示微整型 </span></span><br><span class="line">	<span class="comment">-- status 0 表示正常 1 休学 2 毕业</span></span><br><span class="line">	status tinyint</span><br><span class="line">);</span><br></pre></td></tr></table></figure>
<h3 id="小结-8">小结</h3>
<ol type="1">
<li>创建表语句：CREATE TABLE 表名 (字段名 类型, 字段名
字段类型...);</li>
<li>常用数据类型：int, double, varchar, date</li>
</ol>
<h2 id="ddl查看表">13、DDL查看表</h2>
<h3 id="目标-10">目标</h3>
<ol type="1">
<li>能够查看某个数据库中的所有表</li>
<li>能够查看表结构</li>
</ol>
<h3 id="讲解-10">讲解</h3>
<ol type="1">
<li><p>查看某个数据库中的所有表</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SHOW</span> TABLES;</span><br></pre></td></tr></table></figure></li>
<li><p>查看表结构</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">DESC</span> 表名;</span><br></pre></td></tr></table></figure></li>
<li><p>查看创建表的SQL语句</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SHOW</span> <span class="keyword">CREATE</span> <span class="keyword">TABLE</span> 表名;</span><br></pre></td></tr></table></figure></li>
</ol>
<p>具体操作： * 查看mysql数据库中的所有表 <figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SHOW</span> TABLES;</span><br></pre></td></tr></table></figure> <img data-src="img/查看某个数据库中的所有表.png" alt="查看某个数据库中的所有表"></p>
<ul>
<li>查看student表的结构 <figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">DESC</span> student;</span><br></pre></td></tr></table></figure> <img data-src="img/查看student表的结构.png" alt="查看student表的结构"></li>
<li>查看student的创建表SQL语句 <figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SHOW</span> <span class="keyword">CREATE</span> <span class="keyword">TABLE</span> student;</span><br></pre></td></tr></table></figure> <img data-src="img/查看student的创建表SQL语句.png" alt="查看student的创建表SQL语句"></li>
</ul>
<h3 id="小结-9">小结</h3>
<ol type="1">
<li>查看某个数据库中的所有表：show tables;</li>
<li>查看表结构：desc 表名;</li>
<li>查看创建表的SQL语句：show create table 表名;</li>
</ol>
<h2 id="ddl删除表">14、DDL删除表</h2>
<h3 id="目标-11">目标</h3>
<ol type="1">
<li>能够掌握删除表语法</li>
<li>能够掌握快速创建一个表结构相同的表</li>
</ol>
<h3 id="讲解-11">讲解</h3>
<h4 id="快速创建一个表结构相同的表">快速创建一个表结构相同的表</h4>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">CREATE</span> <span class="keyword">TABLE</span> 表名 <span class="keyword">LIKE</span> 其他表;</span><br></pre></td></tr></table></figure>
<p>具体操作：</p>
<ul>
<li><p>创建s1表，s1表结构和student表结构相同</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">CREATE</span> <span class="keyword">TABLE</span> s1 <span class="keyword">LIKE</span> student;</span><br></pre></td></tr></table></figure></li>
</ul>
<h4 id="删除表">删除表</h4>
<ol type="1">
<li><p>直接删除表</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">DROP</span> <span class="keyword">TABLE</span> 表名;</span><br></pre></td></tr></table></figure></li>
<li><p>判断表是否存在并删除表</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">DROP</span> <span class="keyword">TABLE</span> IF <span class="keyword">EXISTS</span> 表名;</span><br></pre></td></tr></table></figure></li>
</ol>
<p>具体操作： * 直接删除表s1表 <figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">DROP</span> <span class="keyword">TABLE</span> s1;</span><br></pre></td></tr></table></figure> <img data-src="img/直接删除表.png" alt="直接删除表"> * 判断表是否存在并删除s1表
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">DROP</span> <span class="keyword">TABLE</span> IF <span class="keyword">EXISTS</span> s1;</span><br></pre></td></tr></table></figure> <img data-src="img/判断表存在并删除.png" alt="判断表存在并删除"></p>
<h3 id="小结-10">小结</h3>
<ol type="1">
<li>快速创建一个表结构相同的表：CREATE TABLE 表名 LIKE 其他表;</li>
<li>删除表语法：DROP TABLE 表名;</li>
</ol>
<h2 id="ddl修改表结构了解">15、DDL修改表结构(了解)</h2>
<h3 id="目标-12">目标</h3>
<p>能够掌握修改表结构的语法</p>
<h3 id="讲解-12">讲解</h3>
<blockquote>
<p>修改表结构使用不是很频繁，只需要了解，等需要使用的时候再回来查即可 1.
添加表列</p>
</blockquote>
<p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">ALTER</span> <span class="keyword">TABLE</span> 表名 <span class="keyword">ADD</span> 字段名<span class="operator">/</span>列名 类型;</span><br></pre></td></tr></table></figure></p>
<p>具体操作： * 为学生表添加一个新的字段remark,类型为varchar(20)
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">ALTER</span> <span class="keyword">TABLE</span> student <span class="keyword">ADD</span> remark <span class="type">VARCHAR</span>(<span class="number">20</span>);</span><br></pre></td></tr></table></figure> <img data-src="img/添加字段.png" alt="添加字段"></p>
<ol start="2" type="1">
<li><p>修改列类型</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">ALTER</span> <span class="keyword">TABLE</span> 表名 MODIFY 字段名 新的类型;</span><br></pre></td></tr></table></figure>
<p>具体操作：</p>
<ul>
<li>将student表中的remark字段的改成varchar(100) <figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">ALTER</span> <span class="keyword">TABLE</span> student MODIFY remark <span class="type">VARCHAR</span>(<span class="number">100</span>);</span><br></pre></td></tr></table></figure> <img data-src="img/修改字段类型.png" alt="修改字段类型"></li>
</ul></li>
<li><p>修改列名</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">ALTER</span> <span class="keyword">TABLE</span> 表名 CHANGE 旧字段名 新字段名 类型;</span><br></pre></td></tr></table></figure>
<p>具体操作：</p>
<ul>
<li>将student表中的remark字段名改成intro，类型varchar(30) <figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">ALTER</span> <span class="keyword">TABLE</span> student CHANGE remark intro <span class="type">varchar</span>(<span class="number">30</span>);</span><br></pre></td></tr></table></figure>
<img data-src="img/修改表字段名称.png" alt="修改表字段名称"></li>
</ul></li>
<li><p>删除列</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">ALTER</span> <span class="keyword">TABLE</span> 表名 <span class="keyword">DROP</span> 字段名;</span><br></pre></td></tr></table></figure>
<p>具体操作：</p>
<ul>
<li>删除student表中的字段intro <figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">ALTER</span> <span class="keyword">TABLE</span> student <span class="keyword">DROP</span> intro;</span><br></pre></td></tr></table></figure> <img data-src="img/删除字段.png" alt="删除字段"></li>
</ul></li>
<li><p>修改表名</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">RENAME <span class="keyword">TABLE</span> 旧表名 <span class="keyword">TO</span> 新表名;</span><br></pre></td></tr></table></figure>
<p>具体操作：</p>
<ul>
<li>将学生表student改名成student2. <figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">RENAME <span class="keyword">TABLE</span> student <span class="keyword">TO</span> student2;</span><br></pre></td></tr></table></figure> <img data-src="img/修改表名.png" alt="修改表名"></li>
</ul></li>
<li><p>修改字符集</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">ALTER</span> <span class="keyword">TABLE</span> 表名 <span class="type">character</span> <span class="keyword">set</span> 字符集;</span><br></pre></td></tr></table></figure>
<p>具体操作：</p>
<ul>
<li>将sutden2表的编码修改成gbk <figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">ALTER</span> <span class="keyword">TABLE</span> student2 <span class="type">character</span> <span class="keyword">set</span> gbk;</span><br></pre></td></tr></table></figure> <img data-src="img/修改字符集.png" alt="修改字符集"></li>
</ul></li>
</ol>
<h3 id="小结-11">小结</h3>
<ol type="1">
<li>所有修改表前面的语法都是相同的？ALTER TABLE 表名</li>
<li>添加一列：add 字段名 类型</li>
<li>修改类型：modify 字段名 新的类型</li>
<li>修改字段名和类型：change 旧字段名 新字段名 类型</li>
<li>删除一列：drop 字段名</li>
</ol>
<h2 id="dml插入记录重点">16、DML插入记录(重点)</h2>
<h3 id="目标-13">目标</h3>
<p>能够掌握往表中添加记录</p>
<h3 id="讲解-13">讲解</h3>
<p>创建student表包含id,name,age,birthday,sex,address字段。</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">CREATE</span> <span class="keyword">TABLE</span> student (</span><br><span class="line">      id <span class="type">INT</span>,</span><br><span class="line">      name <span class="type">VARCHAR</span>(<span class="number">20</span>),</span><br><span class="line">      age <span class="type">int</span>,</span><br><span class="line">      birthday <span class="type">DATE</span>,</span><br><span class="line">      sex <span class="type">char</span>(<span class="number">2</span>),</span><br><span class="line">      address <span class="type">varchar</span>(<span class="number">50</span>)</span><br><span class="line">);</span><br></pre></td></tr></table></figure>
<h4 id="插入全部字段">插入全部字段</h4>
<ul>
<li><p>所有的字段名都写出来</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">INSERT</span> <span class="comment">-- 表示往表里插入记录</span></span><br><span class="line"><span class="keyword">INSERT</span> <span class="keyword">INTO</span> 表名 (字段名<span class="number">1</span>, 字段名<span class="number">2.</span>..) <span class="keyword">VALUES</span> (字段值<span class="number">1</span>, 字段值<span class="number">2.</span>..);</span><br></pre></td></tr></table></figure></li>
<li><p>不写字段名</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">INSERT</span> <span class="keyword">INTO</span> 表名 <span class="keyword">VALUES</span> (字段值<span class="number">1</span>, 字段值<span class="number">2.</span>..);</span><br></pre></td></tr></table></figure></li>
</ul>
<h4 id="插入部分数据">插入部分数据</h4>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">INSERT</span> <span class="keyword">INTO</span> 表名 (字段名<span class="number">1</span>, 字段名<span class="number">2.</span>..) <span class="keyword">VALUES</span> (字段值<span class="number">1</span>, 字段值<span class="number">2.</span>..);</span><br></pre></td></tr></table></figure>
<p>说明：插入部分数据的时候，要求列名一定书写出来。</p>
<h4 id="批量插入数据">批量插入数据</h4>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">INSERT</span> <span class="keyword">INTO</span> 表名 <span class="keyword">values</span>(字段值<span class="number">1</span>, 字段值<span class="number">2.</span>..),(字段值<span class="number">1</span>, 字段值<span class="number">2.</span>..),(字段值<span class="number">1</span>, 字段值<span class="number">2.</span>..);</span><br></pre></td></tr></table></figure>
<p>没有添加数据的字段会使用NULL</p>
<ol type="1">
<li><p>关键字说明 <figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">INSERT</span> <span class="keyword">INTO</span> 表名 – 表示往哪张表中添加数据</span><br><span class="line">(字段名<span class="number">1</span>, 字段名<span class="number">2</span>, …)  <span class="comment">--  要给哪些字段设置值</span></span><br><span class="line"><span class="keyword">VALUES</span> (值<span class="number">1</span>, 值<span class="number">2</span>, …); <span class="comment">-- 设置具体的值</span></span><br><span class="line">注意：使用   <span class="keyword">select</span> <span class="operator">*</span> <span class="keyword">from</span> 表名 <span class="comment">--查看该表的所有信息。</span></span><br></pre></td></tr></table></figure></p></li>
<li><p>具体操作:</p>
<ul>
<li><p>插入部分数据，往学生表中添加 id, name, age, sex数据
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">INSERT</span> <span class="keyword">INTO</span> student (id, name, age, sex) <span class="keyword">VALUES</span> (<span class="number">1</span>, <span class="string">&#x27;张三&#x27;</span>, <span class="number">20</span>, <span class="string">&#x27;男&#x27;</span>);</span><br></pre></td></tr></table></figure> <img data-src="img/添加部分数据.png" alt="添加部分数据"></p></li>
<li><p>向表中插入所有字段</p>
<ul>
<li><p>所有的字段名都写出来 <figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">INSERT</span> <span class="keyword">INTO</span> student (id, name, age, sex, address) <span class="keyword">VALUES</span> (<span class="number">2</span>, <span class="string">&#x27;李四&#x27;</span>,  <span class="number">23</span>, <span class="string">&#x27;女&#x27;</span>, <span class="string">&#x27;广州&#x27;</span>);</span><br></pre></td></tr></table></figure> <img data-src="img/所有字段都添加数据.png" alt="所有字段都添加数据"></p></li>
<li><p>不写字段名 <figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">INSERT</span> <span class="keyword">INTO</span> student <span class="keyword">VALUES</span> (<span class="number">3</span>, <span class="string">&#x27;王五&#x27;</span>, <span class="number">18</span>, <span class="string">&#x27;男&#x27;</span>, <span class="string">&#x27;北京&#x27;</span>);</span><br></pre></td></tr></table></figure> <img data-src="img/添加所有字段数据.png" alt="添加所有字段数据"></p></li>
</ul>
<p>批量插入数据</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">INSERT</span> <span class="keyword">INTO</span> student <span class="keyword">VALUES</span> (<span class="number">4</span>, <span class="string">&#x27;赵六&#x27;</span>, <span class="number">18</span>, <span class="string">&#x27;男&#x27;</span>, <span class="string">&#x27;上海&#x27;</span>),(<span class="number">5</span>, <span class="string">&#x27;田七&#x27;</span>, <span class="number">20</span>, <span class="string">&#x27;男&#x27;</span>, <span class="string">&#x27;杭州&#x27;</span>);</span><br></pre></td></tr></table></figure></li>
</ul></li>
</ol>
<h4 id="注意">注意</h4>
<blockquote>
<ul>
<li><p>值与列一一对应。有多少个列，就需要写多少个值。如果某一个列没有值。可以使用null。表示插入空。</p></li>
<li><p>值的数据类型，与列被定义的数据类型要相匹配。并且值的长度，不能够超过定义的列的长度。</p></li>
<li><p>字符串：插入字符类型的数据，建议写英文单引号括起来。在mysql中，使用单引号表示字符串</p></li>
<li><p>date 时间类型的数据也得使用英文单引号括起来：
如’yyyy-MM-dd’</p></li>
</ul>
</blockquote>
<h3 id="小结-12">小结</h3>
<p>1.向表中添加一条完整记录： 所有的字段都写出来: INSERT INTO 表名
(字段1, 字段2, ....) VALUES (值1, 值2, ...);</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">insert into student(id,name,birthday,sex,address) values(1,&quot;幂幂&quot;,&#x27;2000-10-10&#x27;,&#x27;女&#x27;,&#x27;上海&#x27;);</span><br></pre></td></tr></table></figure>
<p><strong>2.不写字段名: INSERT INTO 表名 VALUES (值1, 值2,
...);</strong>开发使用</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">insert into student values(3,&#x27;冰冰&#x27;,null,&#x27;女&#x27;,&#x27;北京&#x27;);</span><br></pre></td></tr></table></figure>
<p>3.向表中添加一条记录部分列：必须写字段名,否则不知道添哪个字段. INSERT
INTO 表名 (字段1, 字段2, ....) VALUES (值1, 值2, ...);</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">insert into student(id,name,address) values(2,&#x27;岩岩&#x27;,&#x27;湖南&#x27;);</span><br></pre></td></tr></table></figure>
<p>4.批量插入数据</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">INSERT INTO 表名 values(字段值1, 字段值2...),(字段值1, 字段值2...),(字段值1, 字段值2...)</span><br></pre></td></tr></table></figure>
<h2 id="dml更新表记录">17、DML更新表记录</h2>
<h3 id="目标-14">目标</h3>
<p>能够掌握更新表记录</p>
<h3 id="讲解-14">讲解</h3>
<ol type="1">
<li><p>不带条件修改数据</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">UPDATE</span> 表名 <span class="keyword">SET</span> 字段名<span class="operator">=</span>新的值,字段名<span class="operator">=</span>新的值,..;</span><br></pre></td></tr></table></figure></li>
<li><p>带条件修改数据</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">UPDATE</span> 表名 <span class="keyword">SET</span> 字段名<span class="operator">=</span>新的值,字段名<span class="operator">=</span>新的值,.. <span class="keyword">WHERE</span> 条件</span><br></pre></td></tr></table></figure></li>
<li><p>关键字说明 <figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">UPDATE</span>: 表示修改记录 </span><br><span class="line"><span class="keyword">SET</span>: 要改哪个字段</span><br><span class="line"><span class="keyword">WHERE</span>: 设置条件</span><br></pre></td></tr></table></figure></p></li>
<li><p>具体操作：</p>
<ul>
<li><p>不带条件修改数据，将所有的性别改成女 <figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">UPDATE</span> student <span class="keyword">SET</span> sex<span class="operator">=</span><span class="string">&#x27;女&#x27;</span>;</span><br></pre></td></tr></table></figure> <img data-src="img/修改所有数据.png" alt="修改所有数据"></p></li>
<li><p>带条件修改数据，将id号为2的学生性别改成男 <figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">UPDATE</span> student <span class="keyword">SET</span> sex<span class="operator">=</span><span class="string">&#x27;男&#x27;</span> <span class="keyword">WHERE</span> id<span class="operator">=</span><span class="number">2</span>;</span><br></pre></td></tr></table></figure> <img data-src="img/带条件修改.png" alt="带条件修改"></p></li>
<li><p>一次修改多个列，把id为3的学生，年龄改成26岁，address改成北京
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">UPDATE</span> student <span class="keyword">SET</span> age<span class="operator">=</span><span class="number">26</span>, address<span class="operator">=</span><span class="string">&#x27;北京&#x27;</span> <span class="keyword">WHERE</span> id<span class="operator">=</span><span class="number">3</span>;</span><br></pre></td></tr></table></figure> <img data-src="img/一次性修改2个字段.png" alt="一次性修改2个字段"></p></li>
</ul></li>
</ol>
<h3 id="小结-13">小结</h3>
<ol type="1">
<li>不带条件的更新数据库记录：UPDATE 表名 SET 字段名=新的值;</li>
<li>带条件：UPDATE 表名 SET 字段名=新的值 WHERE 条件;</li>
</ol>
<h2 id="dml删除表记录">18、DML删除表记录</h2>
<h3 id="目标-15">目标</h3>
<p>能够掌握删除表记录</p>
<h3 id="讲解-15">讲解</h3>
<ol type="1">
<li><p>不带条件删除数据</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">DELETE</span> <span class="comment">-- 删除记录</span></span><br><span class="line"><span class="keyword">DELETE</span> <span class="keyword">FROM</span> 表名;</span><br><span class="line">表还在，可以操作，只是删除数据。</span><br></pre></td></tr></table></figure></li>
<li><p>带条件删除数据</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">DELETE</span> <span class="keyword">FROM</span> 表名 <span class="keyword">WHERE</span> 条件;</span><br></pre></td></tr></table></figure></li>
<li><p>truncate删除表记录 属于DDL</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">TRUNCATE</span> <span class="keyword">TABLE</span> 表名;</span><br></pre></td></tr></table></figure>
<blockquote>
truncate和delete的区别：
<ul>
<li>delete是将表中的数据一条一条删除</li>
<li>truncate是将整个表摧毁，重新创建一个新的表,新的表结构和原来表结构一模一样
<img data-src="img/truncate.png" alt="truncate"></li>
</ul>
</blockquote></li>
<li><p>具体操作：</p>
<ul>
<li><p>带条件删除数据，删除id为3的记录 <figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">DELETE</span> <span class="keyword">FROM</span> student <span class="keyword">WHERE</span> id<span class="operator">=</span><span class="number">3</span>;</span><br></pre></td></tr></table></figure></p>
<figure>
<img data-src="img/删除满足条件的记录.png" alt="删除满足条件的记录">
<figcaption aria-hidden="true">删除满足条件的记录</figcaption>
</figure></li>
<li><p>带条件删除数据，删除id为1和2的记录</p></li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">DELETE FROM student WHERE id in(1,2);</span><br></pre></td></tr></table></figure>
<ul>
<li><p>不带条件删除数据,删除表中的所有数据</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">DELETE</span> <span class="keyword">FROM</span> student;</span><br></pre></td></tr></table></figure>
<figure>
<img data-src="img/删除所有记录.png" alt="删除所有记录">
<figcaption aria-hidden="true">删除所有记录</figcaption>
</figure></li>
</ul></li>
</ol>
<h3 id="小结-14">小结</h3>
<ol type="1">
<li>指定条件删除：DELETE FROM 表名 WHERE 条件;</li>
<li>没有条件删除所有的记录：DELETE FROM 表名;</li>
<li>删除表结构再创建表：TRUNCATE TABLE 表名;</li>
</ol>
<h2 id="dql没有条件的简单查询">19、DQL没有条件的简单查询</h2>
<h3 id="目标-16">目标</h3>
<p>能够掌握简单查询</p>
<h3 id="讲解-16">讲解</h3>
<blockquote>
<p>注意：查询不会对数据库中的数据进行修改，只是一种显示数据的方式。 ####
查询表中所有列数据 1. 写出查询每列的名称 <figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> <span class="comment">-- 表示查询</span></span><br><span class="line"><span class="keyword">SELECT</span> 字段名<span class="number">1</span>, 字段名<span class="number">2</span>, ... <span class="keyword">FROM</span> 表名;</span><br></pre></td></tr></table></figure> 具体操作：</p>
</blockquote>
<p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> id, name ,age, sex, address <span class="keyword">FROM</span> student;</span><br></pre></td></tr></table></figure> <img data-src="img/查询所有列.png" alt="查询所有列"></p>
<ol start="2" type="1">
<li><p>使用*表示所有列</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> <span class="operator">*</span> <span class="keyword">FROM</span> 表名;</span><br></pre></td></tr></table></figure>
<p>具体操作：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> <span class="operator">*</span> <span class="keyword">FROM</span> student;</span><br></pre></td></tr></table></figure>
<figure>
<img data-src="img/查询所有列.png" alt="查询所有列">
<figcaption aria-hidden="true">查询所有列</figcaption>
</figure></li>
</ol>
<h4 id="查询表中指定列数据">查询表中指定列数据</h4>
<p>查询指定列的数据,多个列之间以逗号分隔 <figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> 字段名<span class="number">1</span>, 字段名<span class="number">2</span> <span class="keyword">FROM</span> 表名;</span><br></pre></td></tr></table></figure></p>
<p>具体操作： 查询student表中的name 和 age 列</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> name, age <span class="keyword">FROM</span> student;</span><br></pre></td></tr></table></figure>
<figure>
<img data-src="img/查询指定字段.png" alt="查询指定字段">
<figcaption aria-hidden="true">查询指定字段</figcaption>
</figure>
<h4 id="别名查询">别名查询</h4>
<ol type="1">
<li><p>查询时给列、表指定别名需要使用AS关键字</p></li>
<li><p>使用别名的好处是方便观看和处理查询到的数据
<code>SELECT 字段名1 AS 别名, 字段名2 AS 别名... FROM 表名;</code>
<code>SELECT 字段名1 AS 别名, 字段名2 AS 别名... FROM 表名 AS 表别名;</code>
注意:</p>
<blockquote>
<p>查询给表取别名目前还看不到效果，需要到多表查询的时候才能体现出好处
AS关键字可以省略</p>
</blockquote></li>
<li><p>具体操作：</p>
<ul>
<li>查询sudent表中name 和 age
列，name列的别名为”姓名”，age列的别名为”年龄” <figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> NAME <span class="keyword">AS</span> 姓名, age <span class="keyword">AS</span> 年龄 <span class="keyword">FROM</span> student;</span><br></pre></td></tr></table></figure> <img data-src="img/查询字段别名.png" alt="查询字段别名"></li>
</ul></li>
</ol>
<h4 id="清除重复值">清除重复值</h4>
<ol type="1">
<li><p>查询指定列并且结果不出现重复数据</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> <span class="keyword">DISTINCT</span> 字段名,字段名,.. <span class="keyword">FROM</span> 表名;</span><br></pre></td></tr></table></figure></li>
<li><p>具体操作：</p>
<ul>
<li>查询address列并且结果不出现重复的address <figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> <span class="keyword">DISTINCT</span> address 城市 <span class="keyword">FROM</span> student;</span><br></pre></td></tr></table></figure> <img data-src="img/1550289641391.png" alt="1550289641391"></li>
</ul></li>
</ol>
<h4 id="查询结果参与运算">查询结果参与运算</h4>
<ol type="1">
<li><p>某列数据和固定值运算</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> 列名<span class="number">1</span> <span class="keyword">FROM</span> 表名;</span><br><span class="line"><span class="keyword">SELECT</span> 列名<span class="number">1</span> <span class="operator">+</span> 固定值 <span class="keyword">FROM</span> 表名;</span><br></pre></td></tr></table></figure></li>
<li><p>某列数据和其他列数据参与运算</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> 列名<span class="number">1</span> <span class="operator">+</span> 列名<span class="number">2</span> <span class="keyword">FROM</span> 表名;</span><br></pre></td></tr></table></figure>
<blockquote>
<p>注意: 参与运算的必须是数值类型</p>
</blockquote></li>
<li><p>需求：</p>
<ul>
<li>添加数学，英语成绩列，给每条记录添加对应的数学和英语成绩</li>
<li>查询的时候将数学和英语的成绩相加</li>
</ul></li>
<li><p>实现：</p></li>
</ol>
<ul>
<li><p>修改student表结构,添加数学和英语成绩列 <figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">ALTER</span> <span class="keyword">TABLE</span> student <span class="keyword">ADD</span> math <span class="type">INT</span>;</span><br><span class="line"><span class="keyword">ALTER</span> <span class="keyword">TABLE</span> student <span class="keyword">ADD</span> english <span class="type">INT</span>;</span><br></pre></td></tr></table></figure></p></li>
<li><p>给每条记录添加对应的数学和英语成绩 <img data-src="img/添加数学和英语成绩.png" alt="添加数学和英语成绩"></p></li>
<li><p>查询math + english的和 <figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> math <span class="operator">+</span> english <span class="keyword">FROM</span> student;</span><br></pre></td></tr></table></figure> <img data-src="img/查询math和english的和.png" alt="查询math和english的和"></p>
<blockquote>
<p>结果确实将每条记录的math和english相加，但是效果不好看</p>
</blockquote></li>
<li><p>查询math + english的和使用别名”总成绩” <figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> math <span class="operator">+</span> english 总成绩 <span class="keyword">FROM</span> student;</span><br></pre></td></tr></table></figure> <img data-src="img/组合查询结果取别名.png" alt="组合查询结果取别名"></p></li>
<li><p>查询所有列与math + english的和并使用别名”总成绩” <figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> <span class="operator">*</span>, math <span class="operator">+</span> english 总成绩 <span class="keyword">FROM</span> student;</span><br></pre></td></tr></table></figure>
<img data-src="img/查询所有列数据和参与运算.png" alt="查询所有列数据和参与运算"></p></li>
<li><p>查询姓名、年龄，将每个人的数学增加10分 <figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> name, age,math <span class="operator">+</span> <span class="number">10</span> <span class="keyword">FROM</span> student;</span><br></pre></td></tr></table></figure></p></li>
</ul>
<h3 id="小结-15">小结</h3>
<ol type="1">
<li>简单查询格式：SELECT 字段名,字段名.... FROM 表名;</li>
<li>定义别名：SELECT 字段名 AS 别名 FROM 表名;</li>
<li>去除重复行：SELECT DISTINCT 字段名 FROM 表名;</li>
<li>数值列，可以进行计算，不会影响表中数据</li>
</ol>
<table>
<colgroup>
<col style="width: 25%">
<col style="width: 74%">
</colgroup>
<thead>
<tr class="header">
<th>DML和简单DQL语句操作</th>
<th>关键字</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>添加</td>
<td>INSERT INTO 表名 (字段名...) VALUES (值...);</td>
</tr>
<tr class="even">
<td>修改</td>
<td>UPDATE 表名 SET 字段名=新的值 ,字段名=新的值..WHERE 条件;</td>
</tr>
<tr class="odd">
<td>删除</td>
<td>DELETE FROM 表名 WHERE 条件; truncate table 表名</td>
</tr>
<tr class="even">
<td>查询</td>
<td>SELETE 字段名,字段名 FROM 表名;</td>
</tr>
</tbody>
</table>
<h2 id="蠕虫复制了解课上不讲解">20、蠕虫复制(了解，课上不讲解)</h2>
<h3 id="目标-17">目标</h3>
<p>了解蠕虫复制</p>
<h3 id="讲解-17">讲解</h3>
<p>什么是蠕虫复制：在已有的数据基础之上，将原来的数据进行复制，插入到对应的表中
语法格式：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">insert</span> <span class="keyword">into</span> 表名<span class="number">1</span> <span class="keyword">select</span> <span class="operator">*</span> <span class="keyword">from</span> 表名<span class="number">2</span>;</span><br></pre></td></tr></table></figure>
<p>作用:将<code>表名2</code>中的数据复制到<code>表名1</code>中</p>
<p>具体操作:</p>
<ul>
<li>创建student2表，student2结构和student表结构一样</li>
</ul>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">create</span> <span class="keyword">table</span> student2 <span class="keyword">like</span> student;</span><br></pre></td></tr></table></figure>
<ul>
<li>将student表中的数据添加到student2表中</li>
</ul>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">insert</span> <span class="keyword">into</span> student2 <span class="keyword">select</span> <span class="operator">*</span> <span class="keyword">from</span> student;</span><br></pre></td></tr></table></figure>
<blockquote>
<p>注意：如果只想复制student表中name,age字段数据到student2表中使用如下格式
<code>insert into student2(name, age) SELECT name, age FROM student;</code>
<img data-src="img\蠕虫复制-1597202630793.png" alt="蠕虫复制"></p>
</blockquote>
<h2 id="dql查询语句-条件查询掌握">21、DQL查询语句-条件查询(掌握)</h2>
<h3 id="目标-18">目标</h3>
<p>能够掌握条件查询语法格式</p>
<h3 id="讲解-18">讲解</h3>
<p>​
前面我们的查询都是将所有数据都查询出来，但是有时候我们只想获取到<code>满足条件</code>的数据
语法格式：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> 字段名... <span class="keyword">FROM</span> 表名 <span class="keyword">WHERE</span> 条件;</span><br></pre></td></tr></table></figure>
<p>流程：取出表中的每条数据，满足条件的记录就返回，不满足条件的记录不返回</p>
<h4 id="准备数据">准备数据</h4>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">CREATE</span> <span class="keyword">TABLE</span> student3 (</span><br><span class="line">  id <span class="type">int</span>,</span><br><span class="line">  name <span class="type">varchar</span>(<span class="number">20</span>),</span><br><span class="line">  age <span class="type">int</span>,</span><br><span class="line">  sex <span class="type">varchar</span>(<span class="number">5</span>),</span><br><span class="line">  address <span class="type">varchar</span>(<span class="number">100</span>),</span><br><span class="line">  math <span class="type">int</span>,</span><br><span class="line">  english <span class="type">int</span></span><br><span class="line">);</span><br><span class="line"></span><br><span class="line"><span class="keyword">INSERT</span> <span class="keyword">INTO</span> student3(id,NAME,age,sex,address,math,english) <span class="keyword">VALUES</span> (<span class="number">1</span>,<span class="string">&#x27;马云&#x27;</span>,<span class="number">55</span>,<span class="string">&#x27;男&#x27;</span>,<span class="string">&#x27;杭州&#x27;</span>,<span class="number">66</span>,<span class="number">78</span>),(<span class="number">2</span>,<span class="string">&#x27;马化腾&#x27;</span>,<span class="number">45</span>,<span class="string">&#x27;女&#x27;</span>,<span class="string">&#x27;深圳&#x27;</span>,<span class="number">98</span>,<span class="number">87</span>),(<span class="number">3</span>,<span class="string">&#x27;马景涛&#x27;</span>,<span class="number">55</span>,<span class="string">&#x27;男&#x27;</span>,<span class="string">&#x27;香港&#x27;</span>,<span class="number">56</span>,<span class="number">77</span>),(<span class="number">4</span>,<span class="string">&#x27;柳岩&#x27;</span>,<span class="number">20</span>,<span class="string">&#x27;女&#x27;</span>,<span class="string">&#x27;湖南&#x27;</span>,<span class="number">76</span>,<span class="number">65</span>),(<span class="number">5</span>,<span class="string">&#x27;柳青&#x27;</span>,<span class="number">20</span>,<span class="string">&#x27;男&#x27;</span>,<span class="string">&#x27;湖南&#x27;</span>,<span class="number">86</span>,<span class="keyword">NULL</span>),(<span class="number">6</span>,<span class="string">&#x27;刘德华&#x27;</span>,<span class="number">57</span>,<span class="string">&#x27;男&#x27;</span>,<span class="string">&#x27;香港&#x27;</span>,<span class="number">99</span>,<span class="number">99</span>),(<span class="number">7</span>,<span class="string">&#x27;马德&#x27;</span>,<span class="number">22</span>,<span class="string">&#x27;女&#x27;</span>,<span class="string">&#x27;香港&#x27;</span>,<span class="number">99</span>,<span class="number">99</span>),(<span class="number">8</span>,<span class="string">&#x27;德玛西亚&#x27;</span>,<span class="number">18</span>,<span class="string">&#x27;男&#x27;</span>,<span class="string">&#x27;南京&#x27;</span>,<span class="number">56</span>,<span class="number">65</span>);</span><br></pre></td></tr></table></figure>
<h4 id="比较运算符">比较运算符</h4>
<p><code>&gt;</code>大于 <code>&lt;</code>小于
<code>&lt;=</code>小于等于 <code>&gt;=</code>大于等于 <code>=</code>等于
<code>&lt;&gt;</code>、<code>!=</code>不等于</p>
<p>具体操作：</p>
<ul>
<li>查询math分数大于80分的学生</li>
</ul>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> <span class="operator">*</span> <span class="keyword">FROM</span> student3 <span class="keyword">WHERE</span> math<span class="operator">&gt;</span><span class="number">80</span>;</span><br></pre></td></tr></table></figure>
<p><img data-src="img\where查询01.png"></p>
<ul>
<li>查询english分数小于或等于80分的学生</li>
</ul>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> <span class="operator">*</span> <span class="keyword">FROM</span> student3 <span class="keyword">WHERE</span> english<span class="operator">&lt;=</span><span class="number">80</span>;</span><br></pre></td></tr></table></figure>
<p><img data-src="img\where查询02.png"></p>
<ul>
<li>查询age等于20岁的学生</li>
</ul>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> <span class="operator">*</span> <span class="keyword">FROM</span> student3 <span class="keyword">WHERE</span> age<span class="operator">=</span><span class="number">20</span>;</span><br></pre></td></tr></table></figure>
<p><img data-src="img\where查询03.png"></p>
<ul>
<li>查询age不等于20岁的学生</li>
</ul>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> <span class="operator">*</span> <span class="keyword">FROM</span> student3 <span class="keyword">WHERE</span> age<span class="operator">!=</span><span class="number">20</span>;</span><br><span class="line"><span class="keyword">SELECT</span> <span class="operator">*</span> <span class="keyword">FROM</span> student3 <span class="keyword">WHERE</span> age<span class="operator">&lt;&gt;</span><span class="number">20</span>;</span><br></pre></td></tr></table></figure>
<p><img data-src="img\where查询04.png"></p>
<h4 id="逻辑运算符">逻辑运算符</h4>
<p><code>and(&amp;&amp;)</code> 多个条件同时满足 一假即假
<code>or(||)</code> 多个条件其中一个满足 一真即真 <code>not(!)</code>
不满足 取反</p>
<p>具体操作：</p>
<ul>
<li>查询age大于35且性别为男的学生(两个条件同时满足)</li>
</ul>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> <span class="operator">*</span> <span class="keyword">FROM</span> student3 <span class="keyword">WHERE</span>  age<span class="operator">&gt;</span><span class="number">35</span> <span class="keyword">AND</span> sex<span class="operator">=</span><span class="string">&#x27;男&#x27;</span>;</span><br></pre></td></tr></table></figure>
<p><img data-src="img\where查询05.png"></p>
<ul>
<li>查询age大于35或性别为男的学生(两个条件其中一个满足)</li>
</ul>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> <span class="operator">*</span> <span class="keyword">FROM</span> student333 <span class="keyword">WHERE</span> age<span class="operator">&gt;</span><span class="number">35</span> <span class="keyword">OR</span> sex<span class="operator">=</span><span class="string">&#x27;男&#x27;</span>;</span><br></pre></td></tr></table></figure>
<p><img data-src="img\where查询06.png"></p>
<ul>
<li>查询id是1或3或5的学生</li>
</ul>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> <span class="operator">*</span> <span class="keyword">FROM</span> student3 <span class="keyword">WHERE</span> id<span class="operator">=</span><span class="number">1</span> <span class="keyword">OR</span> id<span class="operator">=</span><span class="number">3</span> <span class="keyword">OR</span> id<span class="operator">=</span><span class="number">5</span>;</span><br></pre></td></tr></table></figure>
<p><img data-src="img\where查询08.png"></p>
<p><strong>in关键字</strong> 语法格式：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> <span class="operator">*</span> <span class="keyword">FROM</span> 表名 <span class="keyword">WHERE</span> 字段 <span class="keyword">in</span> (值<span class="number">1</span>, 值<span class="number">2</span>, 值<span class="number">3</span>);</span><br></pre></td></tr></table></figure>
<p><code>in</code>里面的每个数据都会作为一次条件，只要满足条件的就会显示</p>
<p>具体操作：</p>
<ul>
<li>查询id是1或3或5的学生</li>
</ul>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> <span class="operator">*</span> <span class="keyword">FROM</span> student3 <span class="keyword">WHERE</span> id <span class="keyword">IN</span> (<span class="number">1</span>,<span class="number">3</span>,<span class="number">5</span>);</span><br></pre></td></tr></table></figure>
<p><img data-src="img\where查询08.png"></p>
<ul>
<li>查询id不是1或3或5的学生</li>
</ul>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> <span class="operator">*</span> <span class="keyword">FROM</span> student3 <span class="keyword">WHERE</span> id <span class="keyword">NOT</span> <span class="keyword">IN</span> (<span class="number">1</span>,<span class="number">3</span>,<span class="number">5</span>);</span><br></pre></td></tr></table></figure>
<p><img data-src="img\where查询07.png"></p>
<h4 id="范围">范围</h4>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">BETWEEN</span> 值<span class="number">1</span> <span class="keyword">AND</span> 值<span class="number">2</span> <span class="comment">-- 表示从值1到值2范围，包头又包尾</span></span><br></pre></td></tr></table></figure>
<p>比如：<code>age BETWEEN 80 AND 100</code> 相当于：
<code>age&gt;=80 &amp;&amp; age&lt;=100</code></p>
<p>具体操作：</p>
<ul>
<li>查询english成绩大于等于75，且小于等于90的学生</li>
</ul>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> <span class="operator">*</span> <span class="keyword">FROM</span> student3 <span class="keyword">WHERE</span> english<span class="operator">&gt;=</span><span class="number">75</span> <span class="keyword">AND</span> english<span class="operator">&lt;=</span><span class="number">90</span>;</span><br><span class="line"><span class="keyword">SELECT</span> <span class="operator">*</span> <span class="keyword">FROM</span> student3 <span class="keyword">WHERE</span> english <span class="keyword">BETWEEN</span> <span class="number">75</span> <span class="keyword">AND</span> <span class="number">90</span>;</span><br></pre></td></tr></table></figure>
<p><img data-src="img\where查询09.png"></p>
<h2 id="模糊查询like掌握">22、模糊查询like(掌握)</h2>
<h3 id="目标-19">目标</h3>
<p>能够掌握模糊查询语法格式</p>
<p><img data-src="img\where查询11.png"></p>
<h3 id="讲解-19">讲解</h3>
<p><code>LIKE</code>表示模糊查询</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> <span class="operator">*</span> <span class="keyword">FROM</span> 表名 <span class="keyword">WHERE</span> 字段名 <span class="keyword">LIKE</span> <span class="string">&#x27;通配符字符串&#x27;</span>;</span><br></pre></td></tr></table></figure>
<p>满足<code>通配符字符串</code>规则的数据就会显示出来
所谓的<code>通配符字符串</code>就是<code>含有通配符的字符串</code>
MySQL通配符有两个： <code>%</code>: 表示零个一个多个字符(任意多个字符)
<code>_</code>: 表示一个字符</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">例如：  name <span class="keyword">like</span> <span class="string">&#x27;张%&#x27;</span> 所有姓张学员。 </span><br><span class="line"></span><br><span class="line">name <span class="keyword">like</span> <span class="string">&#x27;%张%&#x27;</span> 只要有张就可以。</span><br><span class="line"></span><br><span class="line">name <span class="keyword">like</span> <span class="string">&#x27;张_&#x27;</span> 所有姓张名字为两个字学员。</span><br><span class="line"></span><br><span class="line">name <span class="keyword">like</span> <span class="string">&#x27;_张_&#x27;</span>  只有中间是张，前面一个字，后面一个字。</span><br></pre></td></tr></table></figure>
<p>具体操作：</p>
<ul>
<li>查询姓马的学生</li>
</ul>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> <span class="operator">*</span> <span class="keyword">FROM</span> student3 <span class="keyword">WHERE</span> NAME <span class="keyword">LIKE</span> <span class="string">&#x27;马%&#x27;</span>;</span><br></pre></td></tr></table></figure>
<p><img data-src="img\where查询10.png"></p>
<ul>
<li>查询姓名中包含'德'字的学生</li>
</ul>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> <span class="operator">*</span> <span class="keyword">FROM</span> student3 <span class="keyword">WHERE</span> NAME <span class="keyword">LIKE</span> <span class="string">&#x27;%德%&#x27;</span>;</span><br></pre></td></tr></table></figure>
<p><img data-src="img\where查询11.png"></p>
<ul>
<li>查询姓马，且姓名有三个字的学生</li>
</ul>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> <span class="operator">*</span> <span class="keyword">FROM</span> student3 <span class="keyword">WHERE</span> NAME <span class="keyword">LIKE</span> <span class="string">&#x27;马__&#x27;</span>;</span><br></pre></td></tr></table></figure>
<p><img data-src="img\where查询12.png"></p>
<h3 id="小结-16">小结</h3>
<p>模糊查询格式: SELECT 字段 FROM 表名 WHERE 字段 LIKE
'通配符字符串';</p>
<p><code>%</code>:表示零个一个多个字符(任意多个字符)
<code>_</code>:表示一个字符</p>
<h2 id="dql查询语句-排序掌握">23、DQL查询语句-排序(掌握)</h2>
<h3 id="目标-20">目标</h3>
<ol type="1">
<li>能够掌握对查询的数据进行排序</li>
</ol>
<p><img data-src="img\orderby01.png"></p>
<h3 id="讲解-20">讲解</h3>
<p>通过<code>ORDER BY</code>子句，可以将查询出的结果进行排序(排序只是显示方式，不会影响数据库中数据的顺序)</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> 字段 <span class="keyword">FROM</span> 表名 <span class="keyword">ORDER</span> <span class="keyword">BY</span> 排序的字段 [<span class="keyword">ASC</span><span class="operator">|</span><span class="keyword">DESC</span>];</span><br></pre></td></tr></table></figure>
<p><strong>ASC</strong>: 升序排序(默认) <strong>DESC</strong>:
降序排序</p>
<ol type="1">
<li>单列排序</li>
</ol>
<p>单列排序就是使用一个字段排序</p>
<p>具体操作：</p>
<ul>
<li>查询所有数据,使用年龄降序排序</li>
</ul>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> <span class="operator">*</span> <span class="keyword">FROM</span> student3 <span class="keyword">ORDER</span> <span class="keyword">BY</span> age <span class="keyword">DESC</span>;</span><br></pre></td></tr></table></figure>
<p><img data-src="img\orderby01.png"></p>
<p>1.2.2 组合排序</p>
<p>组合排序就是先按第一个字段进行排序，如果第一个字段相同，才按第二个字段进行排序，依次类推。
上面的例子中，年龄是有相同的。当年龄相同再使用math进行排序</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> 字段名 <span class="keyword">FROM</span> 表名 <span class="keyword">WHERE</span> 字段<span class="operator">=</span>值 <span class="keyword">ORDER</span> <span class="keyword">BY</span> 字段名<span class="number">1</span> [<span class="keyword">ASC</span><span class="operator">|</span><span class="keyword">DESC</span>], 字段名<span class="number">2</span> [<span class="keyword">ASC</span><span class="operator">|</span><span class="keyword">DESC</span>];</span><br><span class="line">注意： <span class="keyword">order</span> <span class="keyword">by</span> a <span class="keyword">asc</span>,b  <span class="keyword">asc</span></span><br><span class="line">		a, b              </span><br><span class="line">		<span class="number">1</span>, <span class="number">2</span></span><br><span class="line">		<span class="number">1</span>, <span class="number">3</span></span><br><span class="line">		<span class="number">4</span>, <span class="number">5</span></span><br><span class="line">		<span class="number">3</span>, <span class="number">1</span></span><br><span class="line">结果：</span><br><span class="line">       <span class="number">1</span>,<span class="number">2</span></span><br><span class="line">       <span class="number">1</span>,<span class="number">3</span></span><br><span class="line">       <span class="number">3</span>,<span class="number">1</span></span><br><span class="line">       <span class="number">4</span>,<span class="number">5</span></span><br></pre></td></tr></table></figure>
<p>具体操作：</p>
<ul>
<li>查询所有数据,在年龄降序排序的基础上，如果年龄相同再以数学成绩降序排序</li>
</ul>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> <span class="operator">*</span> <span class="keyword">FROM</span> student3 <span class="keyword">ORDER</span> <span class="keyword">BY</span> age <span class="keyword">DESC</span>, math <span class="keyword">DESC</span>;</span><br></pre></td></tr></table></figure>
<p><img data-src="img\orderby02.png"></p>
<h3 id="小结-17">小结</h3>
<ol type="1">
<li>排序的关键字：ORDER BY 字段名</li>
<li>升序：ASC 默认的</li>
<li>降序：DESC</li>
</ol>
<h2 id="dql查询语句-聚合函数掌握">24、DQL查询语句-聚合函数(掌握)</h2>
<h3 id="目标-21">目标</h3>
<p>能够掌握五个聚合函数的使用</p>
<h3 id="讲解-21">讲解</h3>
<p>之前我们做的查询都是横向查询，它们都是根据条件一行一行的进行判断，而使用聚合函数查询是纵向查询，它是对一列的值进行计算，然后返回一个结果值。另外聚合函数会忽略空值。对于null不作为统计。</p>
<p>五个聚合函数：
<code>count</code>：在根据指定的列统计的时候，如果这一列中有null的行，该行
不会被统计在其中。按照列去统计有多少行数据。 <code>sum</code>：
计算指定列的数值和，如果不是数值类型，那么计算结果为0 <code>max</code>：
计算指定列的最大值 <code>min</code>： 计算指定列的最小值
<code>avg</code>： 计算指定列的平均值</p>
<p>聚合函数的使用：写在 SQL语句<code>SELECT</code>后
<code>字段名</code>的地方</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> 字段名... <span class="keyword">FROM</span> 表名;</span><br><span class="line"><span class="keyword">SELECT</span> 聚合函数(字段) <span class="keyword">FROM</span> 表名;</span><br></pre></td></tr></table></figure>
<p>具体操作：</p>
<ul>
<li>查询学生总数</li>
</ul>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> <span class="built_in">COUNT</span>(english) <span class="keyword">FROM</span> student3;</span><br></pre></td></tr></table></figure>
<p><img data-src="img\聚合函数01.png"> 我们发现对于NULL的记录不会统计.</p>
<p>统计数量常用:</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> <span class="built_in">COUNT</span>(<span class="operator">*</span>) <span class="keyword">FROM</span> student3;</span><br></pre></td></tr></table></figure>
<p><img data-src="img\聚合函数02.png"></p>
<ul>
<li>查询年龄大于40的总数</li>
</ul>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> <span class="built_in">COUNT</span>(<span class="operator">*</span>) <span class="keyword">FROM</span> student3 <span class="keyword">WHERE</span> age<span class="operator">&gt;</span><span class="number">40</span>;</span><br></pre></td></tr></table></figure>
<p><img data-src="img\聚合函数03.png"></p>
<ul>
<li>查询数学成绩总分</li>
</ul>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> <span class="built_in">SUM</span>(math) <span class="keyword">FROM</span> student3;</span><br></pre></td></tr></table></figure>
<p><img data-src="img\聚合函数04.png"></p>
<ul>
<li><p>统计数学与英语的总和值。</p>
<p>方法一：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">-- 统计数学与英语的总和值</span></span><br><span class="line"><span class="keyword">select</span> <span class="built_in">sum</span>(math) <span class="operator">+</span> <span class="built_in">sum</span>(english) <span class="keyword">from</span> student3;</span><br></pre></td></tr></table></figure>
<p><img data-src="img\总和值.bmp"></p>
<p>方法二：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">-- 统计数学与英语的总和值</span></span><br><span class="line"><span class="keyword">select</span> <span class="built_in">sum</span>(math <span class="operator">+</span> english) <span class="keyword">from</span> student3;</span><br></pre></td></tr></table></figure>
<p><img data-src="img\总和值2.bmp"></p>
<p>我们发现按照方法二的做法，结果是有问题的。结果少了86。</p>
<p>产生问题的原因：</p>
<p>上述写法会先将每一行的数学分数值和英语分数值进行相加，然后再把每一行的数学分数值和英语分数值相加后的值进行求和。</p>
<p>​
这样写会出现一个问题，因为在mysql中null值和任何值相加为null,导致在进行柳青的数学和英语相加的时候，柳青的数学和英语和值就变为了null。而最后sum求和的时候，就把柳青的数学和英语和值null给排除，因此最后的和值会缺少柳青的数学和英语和值86。</p>
<p>解决方案：在sql语句中我们可以使用数据库提供的函数ifnull(列名,
默认值)来解决上述问题。</p>
<p>ifnull(列名,
默认值)函数表示判断该列名是否为null,如果为null，返回默认值，如果不为null，返回实际的值。</p>
<p>例子：</p>
<p>english 的值是null</p>
<p>​ ifnull(english,2) ====english列的值是null，返回值是 2</p>
<p>english的值是3</p>
<p>​ ifnull(english,2) =====
english列的值不是null，返回实际值是3</p></li>
</ul>
<p><img data-src="img\总和值3.bmp"></p>
<ul>
<li>查询数学成绩最高分</li>
</ul>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> <span class="built_in">MAX</span>(math) <span class="keyword">FROM</span> student3;</span><br></pre></td></tr></table></figure>
<p><img data-src="img\聚合函数06.png"></p>
<ul>
<li>查询数学成绩最低分</li>
</ul>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> <span class="built_in">MIN</span>(math) <span class="keyword">FROM</span> student3;</span><br></pre></td></tr></table></figure>
<p><img data-src="img\聚合函数07.png"></p>
<ul>
<li>查询数学成绩平均分</li>
</ul>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> <span class="built_in">AVG</span>(math) <span class="keyword">FROM</span> student3;</span><br></pre></td></tr></table></figure>
<p><img data-src="img\聚合函数05.png"></p>
<h3 id="小结-18">小结</h3>
<table>
<thead>
<tr class="header">
<th><strong>sum(列名)</strong></th>
<th>求和</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><strong>count(列名)</strong></td>
<td>统计数量 根据列统计行数</td>
</tr>
<tr class="even">
<td><strong>max(列名)</strong></td>
<td>最大值</td>
</tr>
<tr class="odd">
<td><strong>min(列名)</strong></td>
<td>最小值</td>
</tr>
<tr class="even">
<td><strong>avg(列名)</strong></td>
<td>平均值</td>
</tr>
</tbody>
</table>
<h2 id="dql查询语句-分组掌握">25、DQL查询语句-分组(掌握)</h2>
<h3 id="目标-22">目标</h3>
<p>能够对查询后的结果进行分组</p>
<h3 id="讲解-22">讲解</h3>
<p>1.官方定义：分组：
按照某一列或者某几列。把相同的数据，进行合并输出。</p>
<p>2.完整写法：select … from … group by 列名，列名,....</p>
<p>​ 按照某一列进行分组。</p>
<p>​ 目的：仍然是统计使用。</p>
<p>3.分组生活举例：假设去超市买东西，我买了肥皂、洗衣粉、洗衣液、苹果、香蕉、葡萄等。我们在计算总价格之前先对所买的商品进行分类计算价格，然后在相加计算总价格。比如我们先将肥皂、洗衣粉、洗衣液分为一组计算出价格，然后再将苹果、香蕉、葡萄分为一组计算出价格，最后将两组的价格相加就是商品的总价格。</p>
<p>说明：分组其实就是按列进行分类，然后可以对分类完的数据使用聚合函数进行运算。</p>
<p><img data-src="img\分组图解1.bmp"></p>
<p>上述数据表示纸巾和洗衣粉属于不同品牌，但是价格是一样的。</p>
<p>注意：</p>
<p>​ 1、聚合函数：分组之后进行计算；</p>
<p>​ 2、通常 select后面的内容是被分组的列，以及聚合函数；</p>
<p>4.数据准备：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">create table <span class="title function_">orders</span><span class="params">(</span></span><br><span class="line"><span class="params">	id <span class="type">int</span>,</span></span><br><span class="line"><span class="params">	product varchar(<span class="number">20</span>)</span>,</span><br><span class="line">	price <span class="type">float</span></span><br><span class="line">);</span><br><span class="line"></span><br><span class="line">insert into <span class="title function_">orders</span><span class="params">(id,product,price)</span> values(<span class="number">1</span>,<span class="string">&#x27;纸巾&#x27;</span>,<span class="number">16</span>);</span><br><span class="line">insert into <span class="title function_">orders</span><span class="params">(id,product,price)</span> values(<span class="number">2</span>,<span class="string">&#x27;纸巾&#x27;</span>,<span class="number">16</span>);</span><br><span class="line">insert into <span class="title function_">orders</span><span class="params">(id,product,price)</span> values(<span class="number">3</span>,<span class="string">&#x27;红牛&#x27;</span>,<span class="number">5</span>);</span><br><span class="line">insert into <span class="title function_">orders</span><span class="params">(id,product,price)</span> values(<span class="number">4</span>,<span class="string">&#x27;洗衣粉&#x27;</span>,<span class="number">60</span>);</span><br><span class="line">insert into <span class="title function_">orders</span><span class="params">(id,product,price)</span> values(<span class="number">5</span>,<span class="string">&#x27;苹果&#x27;</span>,<span class="number">8</span>);</span><br><span class="line">insert into <span class="title function_">orders</span><span class="params">(id,product,price)</span> values(<span class="number">6</span>,<span class="string">&#x27;洗衣粉&#x27;</span>,<span class="number">60</span>);</span><br></pre></td></tr></table></figure>
<p>5.需求1：查询购买的每种商品的总价。</p>
<p>分析：</p>
<p>查询的内容：product,sum(price) 按照商品名称进行分类。</p>
<p>按照商品分组，应该分成如下几组数据：</p>
<p><img data-src="img\分组图解2.bmp"></p>
<p>分组之后查询的结果应该是：</p>
<p>苹果 8</p>
<p>纸巾 32</p>
<p>红牛 5</p>
<p>洗衣粉 120</p>
<p>最终答案：</p>
<p><img data-src="img\分组图解3.bmp"></p>
<p>说明：先按照product进行分组，分组完成之后再给每一组进行求和。</p>
<p>注意：分组有一个特点：</p>
<p>一旦使用了分组函数，那么最终在显示的时候，只能显示被分组的列或者聚合函数。</p>
<p>举例：修改上述的查询语句：查询结果添加一个id。</p>
<p>select id,product,sum(price) from orders group by product;</p>
<p>结果如下所示：</p>
<p><img data-src="img\分组图解4.bmp"></p>
<p>原来的数据：</p>
<p><img data-src="img\分组图解5.bmp"></p>
<p>说明：</p>
<p>通过查询的结果和原来的数据比较发现，虽然添加id之后可以查询出结果，但是对于纸巾商品来说有问题，查询结果显示id是1，而纸巾的结果的id除了1还有2，同是纸巾，牌子还不一样，所以查询结果有问题。</p>
<p>修改上述数据库表中的数据：</p>
<p>将纸巾id为2的price价格修改为20。</p>
<p><img data-src="img\分组图解6.bmp"></p>
<p>然后修改查询语句，要求是先按照商品名分组，然后在按照价格进行分组。</p>
<p><img data-src="img\分组图解7.bmp"></p>
<p>出现上述结果的原因是：</p>
<p><img data-src="img\分组图解8.bmp"></p>
<p>说明：先按照商品名字进行分组，然后再按照商品的价格进行分组。</p>
<p>需求2：查询每一种商品的总价大于30的商品，并显示总价。</p>
<p>分析：</p>
<p>显示商品和总价，要求条件是商品的总价大于30的商品。</p>
<p>书写的sql语句如下所示：</p>
<p><img data-src="img\分组图解9.bmp"></p>
<p>可是执行上述sql语句时，会报如下错误：</p>
<p><img data-src="img\分组图解10.bmp"></p>
<p>是因为上述的sql语句的使用有错误。</p>
<p>主要原因：在sql语句中的where
后面不允许添加聚合函数，添加就会报上述错误。</p>
<p>那么既然这里不能使用where来解决问题，但是我们还依然要进行过滤，所以在sql语句中，如果分组之后，还需要一些条件。</p>
<p>可以使用having条件，表示分组之后的条件，在having后面可以书写聚合函数。</p>
<p>关于 having 的用法解释：</p>
<p><strong>having必须和group by
一起使用</strong>，having和where的用法一模一样，where怎么使用having就怎么使用，where不能使用的，having也可以使用，比如说where后面不可以使用聚合函数，但是在having后面是可以使用聚合函数的。</p>
<p>修改后的sql语句如下所示：</p>
<p><img data-src="img\分组图解11.bmp"></p>
<p>关于以上sql语句可以实现的最终结果的原因如下所示：</p>
<p><img data-src="img\分组图解12.bmp"></p>
<p>总结：</p>
<p>一、关于group by 和having一起使用的规则如下所示：</p>
<p>group by 列名 having 条件</p>
<p>分组之后加过滤条件。</p>
<p>二、where 和 having 的区别。</p>
<p>1、having 通常与group by 分组结合使用。 where 和分组无关。</p>
<p>2、having 可以书写聚合函数 (聚合函数出现的位置： having 之后)</p>
<p>例如having中的
聚合函数（count，sum，avg，max，min），是不可以出现where条件中。</p>
<p>3、where 是在分组之前进行过滤的。having 是在分组之后进行过滤的。</p>
<p>sql语句举例：</p>
<p><img data-src="img\分组图解13.bmp"></p>
<p>上述sql语句执行顺序如下图所示：</p>
<p><img data-src="img\分组图解14.bmp"></p>
<p>select ... from ... where 条件1 ... group by ... having 条件2 order
by...</p>
<p>执行顺序：</p>
<p>条件1 会先执行过滤</p>
<p>进行分组</p>
<p>条件2进行过滤</p>
<p>开发中什么情况下使用分组？小技巧。</p>
<p>当在需求中遇到每种，每个等字眼的时候就使用分组。</p>
<h3 id="小结-19">小结</h3>
<ol type="1">
<li><p>分组的语法格式？SELECT 字段5 FROM 表名1 WHERE 条件2 GROUP BY
字段3 HAVING 条件4 order by6... ;</p>
<p>123456</p></li>
<li><p>分组的原理？先将相同数据作为一组,返回每组的第一条数据,单独分组没有意义,分组后跟聚合函数操作</p></li>
<li><p>where和having的区别？ having是在分组后对数据进行过滤.
where是在分组前对数据进行过滤 having后面可以使用聚合函数
where后面不可以使用聚合函数</p></li>
<li><p><strong>分组使用：只要带每就分组。</strong></p></li>
</ol>
<h2 id="总结">总结</h2>
<ol type="1">
<li>能够理解数据库的概念 存储数据的仓库</li>
<li>能够安装MySQL数据库 一直下一步:解压,复制 配置MYSQL服务器:下一步</li>
<li>能够启动,关闭及登录MySQL 在服务里面找到MySql,右键启动/关闭
登录MySQL: mysql -uroot -proot</li>
<li>能够使用SQL语句操作数据库 创建数据库: CREATE DATABASE 数据库名;
查看所有数据库: SHOW DATABASES; 删除数据库: DROP DATABASE 数据库名;
<strong>切换数据库: USE 数据库名;</strong></li>
<li>能够使用SQL语句操作表结构 <strong>创建表: CREATE TABLE 表名 (字段名
类型, 字段名 类型, ...);</strong> <strong>查看所有表: SHOW
TABLES;</strong> 修改表: ALTER TABLE 表名; 添加一列: ADD 字段名 类型
修改字段类型: MODIFY 字段名 新的类型; 修改字段名: CHANGE 旧字段名
新字段名 新的类型; 删除一列: DROP 字段名; 修改表名: REANME TABLE 表名 TO
新表名 <strong>删除表: DROP TABLE 表名;</strong></li>
<li><strong>能够使用SQL语句进行数据的添加修改和删除的操作</strong>
添加数据: INSERT INTO 表名 (字段名) VALUES (值); 修改数据: UPDATE 表名
SET 字段名=新的值 WHERE 条件; 删除数据: DELETE FROM 表名 WHERE
条件;</li>
<li>truncate 表名 清空表 属于DDL 删除整个表 重新创建一个表</li>
<li>能够使用SQL语句简单查询数据 SELECT 字段名1, 字段名2, ... FROM
表名;</li>
</ol>
<h1 id="作业">作业:</h1>
<h2 id="作业1实操题">作业1:实操题</h2>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">参考讲义完成mysql数据库的安装与配置</span><br></pre></td></tr></table></figure>
<h2 id="作业2sql题">作业2:sql题</h2>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span>编写sql语句创建demo1数据库</span><br><span class="line"><span class="number">2.</span>编写sql语句在demo1数据库中创建student表</span><br><span class="line">    表字段:</span><br><span class="line">		id <span class="type">int</span>类型</span><br><span class="line">        name 字符串类型,长度<span class="number">50</span></span><br><span class="line">        gender 字符串类型,长度<span class="number">2</span></span><br><span class="line">        address 字符串类型,长度<span class="number">50</span></span><br><span class="line"><span class="number">3.</span>修改表结构,向student表中添加age字段,字段类型为<span class="type">int</span></span><br><span class="line"><span class="number">4.</span>编写sql,向student表中添加三条数据</span><br><span class="line">     <span class="number">1</span>	袁隆平	男	江西	<span class="number">90</span></span><br><span class="line">     <span class="number">2</span>	钟南山	男	福建	<span class="number">84</span></span><br><span class="line">     <span class="number">3</span>	邓稼先	男	安徽	<span class="number">62</span></span><br><span class="line"><span class="number">5.</span>编写sql,修改id为<span class="number">1</span>的数据信息,年龄改为<span class="number">100</span></span><br><span class="line"><span class="number">6.</span>删除id为<span class="number">3</span>的数据信息</span><br></pre></td></tr></table></figure>
<h2 id="作业3">作业3:</h2>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">练习课上相关<span class="keyword">sql</span></span><br></pre></td></tr></table></figure>

    </div>

    
    
    

    <footer class="post-footer">
          <div class="reward-container">
  <div>请我一杯咖啡吧！</div>
  <button>
    赞赏
  </button>
  <div class="post-reward">
      <div>
        <img src="/images/wChat.png" alt="Ethan Liu 微信">
        <span>微信</span>
      </div>

  </div>
</div>

          

<div class="post-copyright">
<ul>
  <li class="post-copyright-author">
      <strong>本文作者： </strong>Ethan Liu
  </li>
  <li class="post-copyright-link">
      <strong>本文链接：</strong>
      <a href="http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/" title="MYSQL基础语法（上）">http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL基础笔记/</a>
  </li>
  <li class="post-copyright-license">
      <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <span class="exturl" data-url="aHR0cHM6Ly9jcmVhdGl2ZWNvbW1vbnMub3JnL2xpY2Vuc2VzL2J5LW5jLXNhLzQuMC8="><i class="fab fa-fw fa-creative-commons"></i>BY-NC-SA</span> 许可协议。转载请注明出处！
  </li>
</ul>
</div>


          <div class="post-tags">
              <a href="/tags/Java/" rel="tag"><i class="fa fa-tag"></i> Java</a>
              <a href="/tags/MySQL/" rel="tag"><i class="fa fa-tag"></i> MySQL</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/2024/04/28/BlogSet/Hexo+NexT%E5%8D%9A%E5%AE%A2%E6%90%AD%E5%BB%BA%E5%8F%8A%E7%BE%8E%E5%8C%96(%E4%BA%8C)/" rel="prev" title="Hexo+NexT博客搭建及美化(二)">
                  <i class="fa fa-angle-left"></i> Hexo+NexT博客搭建及美化(二)
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/2024/04/30/love/%E4%B8%AA%E4%BA%BA%E6%97%A5%E8%AE%B024-04-29/" rel="next" title="个人日记24-04-29">
                  个人日记24-04-29 <i class="fa fa-angle-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






    <div class="comments" id="SOHUCS" sid="05a613935fb775621fcd262ee62939dc"></div>
</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">

  <div class="copyright">
    &copy; 2023-2024 – 
    <span itemprop="copyrightYear">2024</span>
    <span class="with-love">
      <i class="fa fa-heart"></i>
    </span>
    <span class="author" itemprop="copyrightHolder">Is Ethan's</span>
  </div>
<div class="wordcount">
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-line"></i>
    </span>
    <span title="站点总字数">113k</span>
  </span>
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
    <span title="站点阅读时长">6:51</span>
  </span>
</div>
<div class="busuanzi-count">
    <span class="post-meta-item" id="busuanzi_container_site_uv">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-item" id="busuanzi_container_site_pv">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>

    </div>
  </footer>

  
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up fa-lg"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>
  <a role="button" class="book-mark-link book-mark-link-fixed"></a>

  <span class="exturl github-corner" data-url="aHR0cHM6Ly9naXRodWIuY29tL0V0aGFuTGl1Ni8=" title="在 GitHub 上关注我" aria-label="在 GitHub 上关注我"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></span>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/next-theme-pjax/0.6.0/pjax.min.js" integrity="sha256-vxLn1tSKWD4dqbMRyv940UYw4sXgMtYcK6reefzZrao=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.33/fancybox/fancybox.umd.js" integrity="sha256-+2+qOqR8CKoHh/AsVR9k2qaDBKWjYNC2nozhYmv5j9k=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/medium-zoom/1.1.0/medium-zoom.min.js" integrity="sha256-ZgMyDAIYDYGxbcpJcfUnYwNevG/xi9OHKaR/8GK+jWc=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/lozad.js/1.16.0/lozad.min.js" integrity="sha256-mOFREFhqmHeQbXpK2lp4nA3qooVgACfh88fpJftLBbc=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/next-boot.js"></script><script src="/js/bookmark.js"></script><script src="/js/pjax.js"></script>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/hexo-generator-searchdb/1.4.1/search.js" integrity="sha256-1kfA5uHPf65M5cphT2dvymhkuyHPQp5A53EGZOnOLmc=" crossorigin="anonymous"></script>
<script src="/js/third-party/search/local-search.js"></script>

  <script class="next-config" data-name="pdf" type="application/json">{"object_url":{"url":"https://cdnjs.cloudflare.com/ajax/libs/pdfobject/2.2.12/pdfobject.min.js","integrity":"sha256-g2xji1rlE3KsGVClvuxTbcR0Kn2+wtQADSff2Tbb4zA="},"url":"/lib/pdf/web/viewer.html"}</script>
  <script src="/js/third-party/tags/pdf.js"></script>



  <script src="/js/third-party/fancybox.js"></script>



  
  <script data-pjax async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>




  

  <script class="next-config" data-name="enableMath" type="application/json">true</script><script class="next-config" data-name="mathjax" type="application/json">{"enable":true,"tags":"all","js":{"url":"https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.2/es5/tex-mml-chtml.js","integrity":"sha256-MASABpB4tYktI2Oitl4t+78w/lyA+D7b/s9GEP0JOGI="}}</script>
<script src="/js/third-party/math/mathjax.js"></script>


  <script src="https://cdnjs.cloudflare.com/ajax/libs/quicklink/2.3.0/quicklink.umd.js" integrity="sha256-yvJQOINiH9fWemHn0vCA5lsHWJaHs6/ZmO+1Ft04SvM=" crossorigin="anonymous"></script>
  <script class="next-config" data-name="quicklink" type="application/json">{"enable":true,"home":true,"archive":true,"delay":true,"timeout":3000,"priority":true,"url":"http://ethanliu6.github.io/2024/04/30/JavaNotes/MySQL/day01/day01-MySQL%E5%9F%BA%E7%A1%80%E7%AC%94%E8%AE%B0/"}</script>
  <script src="/js/third-party/quicklink.js"></script>
<script class="next-config" data-name="changyan" type="application/json">{"enable":true,"appid":"cyxf6tytI","appkey":"90987f30c4b5248baad5a04c7a6abfe1","count":true}</script>
<script src="/js/third-party/comments/changyan.js"></script>

</body>
</html>
